mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
Fix libpq memory leak during PQreset() --- closePGconn() was not
freeing all transient state of the PGconn object.
This commit is contained in:
parent
5d0a43c585
commit
faea3db958
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.313 2005/06/27 02:04:26 neilc Exp $
|
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.314 2005/07/13 15:25:55 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -1874,6 +1874,8 @@ makeEmptyPGconn(void)
|
|||||||
/*
|
/*
|
||||||
* freePGconn
|
* freePGconn
|
||||||
* - free the PGconn data structure
|
* - free the PGconn data structure
|
||||||
|
*
|
||||||
|
* When changing/adding to this function, see also closePGconn!
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
freePGconn(PGconn *conn)
|
freePGconn(PGconn *conn)
|
||||||
@ -1921,6 +1923,7 @@ freePGconn(PGconn *conn)
|
|||||||
free(conn->krbsrvname);
|
free(conn->krbsrvname);
|
||||||
#endif
|
#endif
|
||||||
/* Note that conn->Pfdebug is not ours to close or free */
|
/* Note that conn->Pfdebug is not ours to close or free */
|
||||||
|
freeaddrinfo_all(conn->addrlist_family, conn->addrlist);
|
||||||
notify = conn->notifyHead;
|
notify = conn->notifyHead;
|
||||||
while (notify != NULL)
|
while (notify != NULL)
|
||||||
{
|
{
|
||||||
@ -1929,7 +1932,6 @@ freePGconn(PGconn *conn)
|
|||||||
notify = notify->next;
|
notify = notify->next;
|
||||||
free(prev);
|
free(prev);
|
||||||
}
|
}
|
||||||
freeaddrinfo_all(conn->addrlist_family, conn->addrlist);
|
|
||||||
pstatus = conn->pstatus;
|
pstatus = conn->pstatus;
|
||||||
while (pstatus != NULL)
|
while (pstatus != NULL)
|
||||||
{
|
{
|
||||||
@ -1952,10 +1954,15 @@ freePGconn(PGconn *conn)
|
|||||||
/*
|
/*
|
||||||
* closePGconn
|
* closePGconn
|
||||||
* - properly close a connection to the backend
|
* - properly close a connection to the backend
|
||||||
|
*
|
||||||
|
* Release all transient state, but NOT the connection parameters.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
closePGconn(PGconn *conn)
|
closePGconn(PGconn *conn)
|
||||||
{
|
{
|
||||||
|
PGnotify *notify;
|
||||||
|
pgParameterStatus *pstatus;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note that the protocol doesn't allow us to send Terminate messages
|
* Note that the protocol doesn't allow us to send Terminate messages
|
||||||
* during the startup phase.
|
* during the startup phase.
|
||||||
@ -1991,6 +1998,27 @@ closePGconn(PGconn *conn)
|
|||||||
* absent */
|
* absent */
|
||||||
conn->asyncStatus = PGASYNC_IDLE;
|
conn->asyncStatus = PGASYNC_IDLE;
|
||||||
pqClearAsyncResult(conn); /* deallocate result and curTuple */
|
pqClearAsyncResult(conn); /* deallocate result and curTuple */
|
||||||
|
freeaddrinfo_all(conn->addrlist_family, conn->addrlist);
|
||||||
|
conn->addrlist = NULL;
|
||||||
|
conn->addr_cur = NULL;
|
||||||
|
notify = conn->notifyHead;
|
||||||
|
while (notify != NULL)
|
||||||
|
{
|
||||||
|
PGnotify *prev = notify;
|
||||||
|
|
||||||
|
notify = notify->next;
|
||||||
|
free(prev);
|
||||||
|
}
|
||||||
|
conn->notifyHead = NULL;
|
||||||
|
pstatus = conn->pstatus;
|
||||||
|
while (pstatus != NULL)
|
||||||
|
{
|
||||||
|
pgParameterStatus *prev = pstatus;
|
||||||
|
|
||||||
|
pstatus = pstatus->next;
|
||||||
|
free(prev);
|
||||||
|
}
|
||||||
|
conn->pstatus = NULL;
|
||||||
if (conn->lobjfuncs)
|
if (conn->lobjfuncs)
|
||||||
free(conn->lobjfuncs);
|
free(conn->lobjfuncs);
|
||||||
conn->lobjfuncs = NULL;
|
conn->lobjfuncs = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user