Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfaea3db

Browse files
committed
Fix libpq memory leak during PQreset() --- closePGconn() was not
freeing all transient state of the PGconn object.
1 parent5d0a43c commitfaea3db

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.313 2005/06/27 02:04:26 neilc Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.314 2005/07/13 15:25:55 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1874,6 +1874,8 @@ makeEmptyPGconn(void)
18741874
/*
18751875
* freePGconn
18761876
* - free the PGconn data structure
1877+
*
1878+
* When changing/adding to this function, see also closePGconn!
18771879
*/
18781880
staticvoid
18791881
freePGconn(PGconn*conn)
@@ -1921,6 +1923,7 @@ freePGconn(PGconn *conn)
19211923
free(conn->krbsrvname);
19221924
#endif
19231925
/* Note that conn->Pfdebug is not ours to close or free */
1926+
freeaddrinfo_all(conn->addrlist_family,conn->addrlist);
19241927
notify=conn->notifyHead;
19251928
while (notify!=NULL)
19261929
{
@@ -1929,7 +1932,6 @@ freePGconn(PGconn *conn)
19291932
notify=notify->next;
19301933
free(prev);
19311934
}
1932-
freeaddrinfo_all(conn->addrlist_family,conn->addrlist);
19331935
pstatus=conn->pstatus;
19341936
while (pstatus!=NULL)
19351937
{
@@ -1952,10 +1954,15 @@ freePGconn(PGconn *conn)
19521954
/*
19531955
* closePGconn
19541956
* - properly close a connection to the backend
1957+
*
1958+
* Release all transient state, but NOT the connection parameters.
19551959
*/
19561960
staticvoid
19571961
closePGconn(PGconn*conn)
19581962
{
1963+
PGnotify*notify;
1964+
pgParameterStatus*pstatus;
1965+
19591966
/*
19601967
* Note that the protocol doesn't allow us to send Terminate messages
19611968
* during the startup phase.
@@ -1991,6 +1998,27 @@ closePGconn(PGconn *conn)
19911998
* absent */
19921999
conn->asyncStatus=PGASYNC_IDLE;
19932000
pqClearAsyncResult(conn);/* deallocate result and curTuple */
2001+
freeaddrinfo_all(conn->addrlist_family,conn->addrlist);
2002+
conn->addrlist=NULL;
2003+
conn->addr_cur=NULL;
2004+
notify=conn->notifyHead;
2005+
while (notify!=NULL)
2006+
{
2007+
PGnotify*prev=notify;
2008+
2009+
notify=notify->next;
2010+
free(prev);
2011+
}
2012+
conn->notifyHead=NULL;
2013+
pstatus=conn->pstatus;
2014+
while (pstatus!=NULL)
2015+
{
2016+
pgParameterStatus*prev=pstatus;
2017+
2018+
pstatus=pstatus->next;
2019+
free(prev);
2020+
}
2021+
conn->pstatus=NULL;
19942022
if (conn->lobjfuncs)
19952023
free(conn->lobjfuncs);
19962024
conn->lobjfuncs=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp