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 */
18781880static void
18791881freePGconn (PGconn * conn )
@@ -1921,6 +1923,7 @@ freePGconn(PGconn *conn)
19211923free (conn -> krbsrvname );
19221924#endif
19231925/* Note that conn->Pfdebug is not ours to close or free */
1926+ freeaddrinfo_all (conn -> addrlist_family ,conn -> addrlist );
19241927notify = conn -> notifyHead ;
19251928while (notify != NULL )
19261929{
@@ -1929,7 +1932,6 @@ freePGconn(PGconn *conn)
19291932notify = notify -> next ;
19301933free (prev );
19311934}
1932- freeaddrinfo_all (conn -> addrlist_family ,conn -> addrlist );
19331935pstatus = conn -> pstatus ;
19341936while (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 */
19561960static void
19571961closePGconn (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 */
19921999conn -> asyncStatus = PGASYNC_IDLE ;
19932000pqClearAsyncResult (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 ;
19942022if (conn -> lobjfuncs )
19952023free (conn -> lobjfuncs );
19962024conn -> lobjfuncs = NULL ;