pgpool2.git / summary / log / commit / refs

commit    4e2189b75d9840f5d948618402924fb1410bb84a
Author:   Tatsuo Ishii <ishii@sraoss.co.jp>
Date:     Tue Sep 24 23:49:48 2019 +0000

    Fix memory leak while attempting to connect to backend.
    
    If no backend is up and running, memory for copy of startup packet
    will be lost. This was brought by commit cdb49d3b7. Per coverity.


src/protocol/child.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/protocol/child.c b/src/protocol/child.c index aa76d5c56..2473c969b 100644 --- a/src/protocol/child.c +++ b/src/protocol/child.c @@ -965,7 +965,8 @@ StartupPacketCopy(StartupPacket *sp) static POOL_CONNECTION_POOL * connect_backend(StartupPacket *sp, POOL_CONNECTION * frontend) { POOL_CONNECTION_POOL *backend; - StartupPacket *topmem_sp; + StartupPacket *volatile topmem_sp = NULL; + volatile bool topmem_sp_set = false; int i; /* connect to the backend */ @@ -1005,6 +1006,7 @@ static POOL_CONNECTION_POOL * connect_backend(StartupPacket *sp, POOL_CONNECTION * save startup packet info */ CONNECTION_SLOT(backend, i)->sp = topmem_sp; + topmem_sp_set = true; /* send startup packet */ send_startup_packet(CONNECTION_SLOT(backend, i)); @@ -1028,10 +1030,17 @@ static POOL_CONNECTION_POOL * connect_backend(StartupPacket *sp, POOL_CONNECTION PG_CATCH(); { pool_discard_cp(sp->user, sp->database, sp->major); + topmem_sp = NULL; PG_RE_THROW(); } PG_END_TRY(); + /* At this point, we need to free previously allocated memory for the + * startup packet if no backend is up. + */ + if (!topmem_sp_set && topmem_sp != NULL) + pfree(topmem_sp); + return backend; } [parent: 51e68842c75e]