pgpool2.git / summary / log / commit / refs
commit ebbf0da7645889c6edc2cc9fe1fb24079c0aa74e
Author: Tatsuo Ishii <ishii@postgresql.org>
Date: Wed Nov 23 08:28:58 2011 +0000
Fix memory leak in raw mode. This is essentially same as the fix
made for 3.0.5 (commit 19a4ea9215da0b61728741fc0da2271958b09238).
pool_proto_modules.c | 50 ++++++++++++++++++++++++++------------------------
pool_query_cache.c | 1 -
pool_rewrite_query.c | 4 +---
3 files changed, 27 insertions(+), 28 deletions(-)
diff --git a/pool_proto_modules.c b/pool_proto_modules.c
index 5d13b13ea..31e4d3e5e 100644
--- a/pool_proto_modules.c
+++ b/pool_proto_modules.c
@@ -117,6 +117,7 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
POOL_SESSION_CONTEXT *session_context;
POOL_QUERY_CONTEXT *query_context;
+ POOL_MEMORY_POOL *old_context;
/* Get session context */
session_context = pool_get_session_context();
@@ -170,6 +171,10 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
}
}
+ /* switch memory context */
+ old_context = pool_memory;
+ pool_memory = query_context->memory_context;
+
/* parse SQL string */
parse_tree_list = raw_parser(contents);
@@ -299,7 +304,6 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
sp->user, sp->database, remote_ps_data);
set_ps_display(psbuf, false);
- free_parser();
pool_query_context_destroy(query_context);
pool_set_skip_reading_from_backends();
return POOL_CONTINUE;
@@ -394,7 +398,7 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
status = insert_lock(frontend, backend, contents, (InsertStmt *)node, lock_kind);
if (status != POOL_CONTINUE)
{
- free_parser();
+ pool_query_context_destroy(query_context);
return status;
}
}
@@ -402,7 +406,7 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
}
else if (REPLICATION && contents == NULL && start_internal_transaction(frontend, backend, node))
{
- free_parser();
+ pool_query_context_destroy(query_context);
return POOL_ERROR;
}
}
@@ -497,16 +501,14 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
{
/* Send query to all DB nodes at once */
status = pool_send_and_wait(query_context, 0, 0);
- /*
- free_parser();
- */
+ /* free_parser(); */
return status;
}
/* Send the query to master node */
if (pool_send_and_wait(query_context, 1, MASTER_NODE_ID) != POOL_CONTINUE)
{
- free_parser();
+ pool_query_context_destroy(query_context);
return POOL_END;
}
}
@@ -516,7 +518,7 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
*/
if (pool_send_and_wait(query_context, -1, MASTER_NODE_ID) != POOL_CONTINUE)
{
- free_parser();
+ pool_query_context_destroy(query_context);
return POOL_END;
}
@@ -525,25 +527,25 @@ POOL_STATUS SimpleQuery(POOL_CONNECTION *frontend,
{
if (pool_send_and_wait(query_context, 1, MASTER_NODE_ID) != POOL_CONTINUE)
{
-/*
- free_parser();
-*/
+ pool_query_context_destroy(query_context);
return POOL_END;
}
}
- free_parser();
+ /* free_parser(); */
}
else
{
if (pool_send_and_wait(query_context, 1, MASTER_NODE_ID) != POOL_CONTINUE)
{
- free_parser();
+ pool_query_context_destroy(query_context);
return POOL_END;
}
-/*
- free_parser();
-*/
+ /* free_parser(); */
}
+
+ /* switch memory context */
+ pool_memory = old_context;
+
return POOL_CONTINUE;
}
@@ -873,13 +875,13 @@ POOL_STATUS Parse(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend,
kind = pool_read_kind(backend);
if (kind != 'Z')
{
- /* free_parser(); */
+ pool_query_context_destroy(query_context);
return POOL_END;
}
if (ReadyForQuery(frontend, backend, 0) != POOL_CONTINUE)
{
- /* free_parser(); */
+ pool_query_context_destroy(query_context);
return POOL_END;
}
@@ -900,7 +902,7 @@ POOL_STATUS Parse(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend,
status = insert_lock(frontend, backend, stmt, (InsertStmt *)query_context->parse_tree, insert_stmt_with_lock);
if (status != POOL_CONTINUE)
{
- /* free_parser(); */
+ pool_query_context_destroy(query_context);
return status;
}
}
@@ -920,7 +922,7 @@ POOL_STATUS Parse(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend,
pool_debug("Parse: waiting for master completing the query");
if (pool_extended_send_and_wait(query_context, "P", len, contents, 1, MASTER_NODE_ID) != POOL_CONTINUE)
{
- /* free_parser(); */
+ pool_query_context_destroy(query_context);
return POOL_END;
}
@@ -933,7 +935,7 @@ POOL_STATUS Parse(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend,
deadlock_detected = detect_deadlock_error(MASTER(backend), MAJOR(backend));
if (deadlock_detected < 0)
{
- /* free_parser(); */
+ pool_query_context_destroy(query_context);
return POOL_END;
}
else
@@ -959,7 +961,7 @@ POOL_STATUS Parse(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend,
if (pool_send_and_wait(error_qc, -1, MASTER_NODE_ID) != POOL_CONTINUE)
{
- /* free_parser(); */
+ pool_query_context_destroy(query_context);
return POOL_END;
}
@@ -971,7 +973,7 @@ POOL_STATUS Parse(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend,
{
if (pool_extended_send_and_wait(query_context, "P", len, contents, -1, MASTER_NODE_ID) != POOL_CONTINUE)
{
- /* free_parser(); */
+ pool_query_context_destroy(query_context);
return POOL_END;
}
}
@@ -980,7 +982,7 @@ POOL_STATUS Parse(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend,
{
if (pool_extended_send_and_wait(query_context, "P", len, contents, 1, MASTER_NODE_ID) != POOL_CONTINUE)
{
- /* free_parser(); */
+ pool_query_context_destroy(query_context);
return POOL_END;
}
}
diff --git a/pool_query_cache.c b/pool_query_cache.c
index 346831b91..677bdaf36 100644
--- a/pool_query_cache.c
+++ b/pool_query_cache.c
@@ -1013,7 +1013,6 @@ POOL_STATUS pool_execute_query_cache_lookup(POOL_CONNECTION *frontend, POOL_CONN
{
free(parsed_query);
parsed_query = NULL;
- free_parser();
}
}
diff --git a/pool_rewrite_query.c b/pool_rewrite_query.c
index 6c152787c..8f8070b1c 100644
--- a/pool_rewrite_query.c
+++ b/pool_rewrite_query.c
@@ -685,7 +685,6 @@ POOL_STATUS pool_do_parallel_query(POOL_CONNECTION *frontend,
* Call parallel exe engine and return status to the upper layer.
*/
POOL_STATUS stats = pool_parallel_exec(frontend,backend,r_query->rewrite_query, node,true);
- free_parser();
pool_unset_query_in_progress();
return stats;
}
@@ -695,7 +694,7 @@ POOL_STATUS pool_do_parallel_query(POOL_CONNECTION *frontend,
r_query = rewrite_query_stmt(node,frontend,backend,r_query);
if(r_query->type == T_InsertStmt)
{
- free_parser();
+ /* free_parser(); */
if(r_query->r_code != INSERT_DIST_NO_RULE) {
pool_unset_query_in_progress();
@@ -705,7 +704,6 @@ POOL_STATUS pool_do_parallel_query(POOL_CONNECTION *frontend,
}
else if(r_query->type == T_SelectStmt)
{
- free_parser();
pool_unset_query_in_progress();
pool_set_skip_reading_from_backends();
return r_query->status;
[parent: ce4f1e536e2e]