From c84f0255704c4d7282591b90170d9012e543d9db Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Sat, 16 Jun 2018 20:44:47 +0900 Subject: [PATCH] Fix memory leaks and null dereference pointed out by Coverity. --- src/auth/pool_hba.c | 3 ++- src/main/main.c | 4 +++- src/protocol/CommandComplete.c | 13 ++++++++++++- src/protocol/pool_process_query.c | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/auth/pool_hba.c b/src/auth/pool_hba.c index 18679c312..7d9a7b96f 100644 --- a/src/auth/pool_hba.c +++ b/src/auth/pool_hba.c @@ -6,7 +6,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Portions Copyright (c) 2003-2017 PgPool Global Development Group + * Portions Copyright (c) 2003-2018 PgPool Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * Permission to use, copy, modify, and distribute this software and @@ -657,6 +657,7 @@ parse_hba_line(TokenizedLine *tok_line, int elevel) line_num, HbaFileName))); *err_msg = psprintf("authentication option not in name=value format: %s", token->string); + pfree(str); return NULL; } diff --git a/src/main/main.c b/src/main/main.c index 7563fa4f3..a87fa2965 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -5,7 +5,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2017 PgPool Global Development Group + * Copyright (c) 2003-2018 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -492,6 +492,8 @@ static char *get_pid_file_path(void) ereport(DEBUG1, (errmsg("pid file location is \"%s\"", new))); + + pfree(conf_file_copy); } else { diff --git a/src/protocol/CommandComplete.c b/src/protocol/CommandComplete.c index 9f0704f91..9e8c265e2 100644 --- a/src/protocol/CommandComplete.c +++ b/src/protocol/CommandComplete.c @@ -5,7 +5,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2017 PgPool Global Development Group + * Copyright (c) 2003-2018 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -134,6 +134,12 @@ POOL_STATUS CommandComplete(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *bac { int status; + if (p1 == NULL) + { + elog(WARNING, "CommandComplete: expected p1 is not NULL"); + return POOL_END; + } + if (command_complete) status = foward_command_complete(frontend, p1, len1); else @@ -166,6 +172,11 @@ POOL_STATUS CommandComplete(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *bac Node *node; char state; + if (session_context->query_context == NULL) + { + elog(WARNING, "expected query_contex is not NULL"); + return POOL_END; + } query = session_context->query_context->query_w_hex; node = pool_get_parse_tree(); state = TSTATE(backend, MASTER_NODE_ID); diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c index c9edcd4b3..cfa4cd9e1 100644 --- a/src/protocol/pool_process_query.c +++ b/src/protocol/pool_process_query.c @@ -4896,7 +4896,7 @@ bool pool_push_pending_data(POOL_CONNECTION *backend) pool_push(backend, &len_save, sizeof(len_save)); len = ntohl(len_save); len -= sizeof(len); - if (len > 0) + if (len > 0 && buf) { pool_push(backend, buf, len); pfree(buf); -- 2.39.5