pgpool2.git / summary / log / commit / refs
commit 514e6fc66cce7331ad241cd60dd742a907adc61d
Author: Tatsuo Ishii <ishii@postgresql.org>
Date: Wed Jun 20 01:25:23 2018 +0000
Fix memory leaks related to pool_extract_error_message().
After 3.4, the function starts to return palloc'ed memory, and the
caller should had been modified so that they pfree the memory returned
by it but actually they had not.
src/auth/pool_auth.c | 15 ++++++++++++---
src/protocol/child.c | 3 ++-
src/protocol/pool_process_query.c | 4 +++-
src/protocol/pool_proto_modules.c | 1 +
4 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/auth/pool_auth.c b/src/auth/pool_auth.c
index aed24f448..5b2b9a5c5 100644
--- a/src/auth/pool_auth.c
+++ b/src/auth/pool_auth.c
@@ -298,6 +298,7 @@ int pool_do_auth(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *cp)
ereport(NOTICE,
(errmsg("notice from backend"),
errdetail("BACKEND NOTICE: \"%s\"",message)));
+ pfree(message);
}
/* process notice message */
if (SimpleForwardToFrontend(kind, frontend, cp))
@@ -325,6 +326,8 @@ int pool_do_auth(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *cp)
(errmsg("authentication failed, backend node replied with an error"),
errdetail("SERVER ERROR:\"%s\"",message?message:"could not extract backend message")));
+ if (message)
+ pfree(message);
break;
default:
@@ -603,13 +606,15 @@ static int do_clear_text_password(POOL_CONNECTION *backend, POOL_CONNECTION *fro
{
if(response == 'E') /* Backend has thrown an error instead */
{
- char* message;
+ char* message = NULL;
if (pool_extract_error_message(false, backend, protoMajor, false, &message) == 1)
{
ereport(ERROR,
(errmsg("clear text password authentication failed"),
errdetail("%s",message?message:"backend throws authentication error")));
}
+ if (message)
+ pfree(message);
}
ereport(ERROR,
(errmsg("clear text password authentication failed"),
@@ -750,13 +755,15 @@ static int do_crypt(POOL_CONNECTION *backend, POOL_CONNECTION *frontend, int rea
{
if(response == 'E') /* Backend has thrown an error instead */
{
- char* message;
+ char* message = NULL;
if (pool_extract_error_message(false, backend, protoMajor, false, &message) == 1)
{
ereport(ERROR,
(errmsg("crypt authentication failed"),
errdetail("%s",message?message:"backend throws authentication error")));
}
+ if (message)
+ pfree(message);
}
ereport(ERROR,
(errmsg("crypt authentication failed"),
@@ -1040,13 +1047,15 @@ static int send_password_packet(POOL_CONNECTION *backend, int protoMajor, char *
{
if(response == 'E') /* Backend has thrown an error instead */
{
- char* message;
+ char* message = NULL;
if (pool_extract_error_message(false, backend, protoMajor, false, &message) == 1)
{
ereport(ERROR,
(errmsg("authentication failed"),
errdetail("%s",message?message:"backend throws authentication error")));
}
+ if (message)
+ pfree(message);
}
ereport(ERROR,
(errmsg("authentication failed"),
diff --git a/src/protocol/child.c b/src/protocol/child.c
index 066b03581..eca917767 100644
--- a/src/protocol/child.c
+++ b/src/protocol/child.c
@@ -285,7 +285,8 @@ void do_child(int *fds)
StartupPacket *sp;
int front_end_fd;
SockAddr saddr;
- /* rest per iteration memory context */
+
+ /* reset per iteration memory context */
MemoryContextSwitchTo(ProcessLoopContext);
MemoryContextResetAndDeleteChildren(ProcessLoopContext);
diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c
index 6baf46760..835716f53 100644
--- a/src/protocol/pool_process_query.c
+++ b/src/protocol/pool_process_query.c
@@ -2048,7 +2048,7 @@ void do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result
{
char *message = NULL;
- if (pool_extract_error_message(false, backend, major, true, &message))
+ if (pool_extract_error_message(false, backend, major, true, &message) == 1)
{
/*
* This is fatal. Because: If we operate extended
@@ -2067,6 +2067,8 @@ void do_query(POOL_CONNECTION *backend, char *query, POOL_SELECT_RESULT **result
errmsg("Backend throw an error message"),
errdetail("Exiting current session because of an error from backend"),
errhint("BACKEND Error: \"%s\"",message?message:"")));
+ if (message)
+ pfree(message);
}
}
diff --git a/src/protocol/pool_proto_modules.c b/src/protocol/pool_proto_modules.c
index 91e37aa0b..d25843b0d 100644
--- a/src/protocol/pool_proto_modules.c
+++ b/src/protocol/pool_proto_modules.c
@@ -3144,6 +3144,7 @@ void per_node_error_log(POOL_CONNECTION_POOL *backend, int node_id, char *query,
ereport(LOG,
(errmsg("%s: DB node id: %d backend pid: %d statement: \"%s\" message: \"%s\"",
prefix, node_id, ntohl(slot->pid), query, message)));
+ pfree(message);
}
}
[parent: bbd49bb8008b]