8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.355 2008/01/01 19:46:00 momjian Exp $
11
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.356 2008/01/29 02:06:30 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -1963,25 +1963,16 @@ makeEmptyPGconn(void)
1963
1963
1964
1964
/*
1965
1965
* freePGconn
1966
- * - free the PGconn data structure
1966
+ * - free an idle (closed) PGconn data structure
1967
1967
*
1968
- * When changing/adding to this function, see also closePGconn!
1968
+ * NOTE: this should not overlap any functionality with closePGconn().
1969
+ * Clearing/resetting of transient state belongs there; what we do here is
1970
+ * release data that is to be held for the life of the PGconn structure.
1971
+ * If a value ought to be cleared/freed during PQreset(), do it there not here.
1969
1972
*/
1970
1973
static void
1971
1974
freePGconn (PGconn * conn )
1972
1975
{
1973
- PGnotify * notify ;
1974
- pgParameterStatus * pstatus ;
1975
-
1976
- if (!conn )
1977
- return ;
1978
-
1979
- pqClearAsyncResult (conn ); /* deallocate result and curTuple */
1980
- if (conn -> sock >= 0 )
1981
- {
1982
- pqsecure_close (conn );
1983
- closesocket (conn -> sock );
1984
- }
1985
1976
if (conn -> pghost )
1986
1977
free (conn -> pghost );
1987
1978
if (conn -> pghostaddr )
@@ -2011,65 +2002,13 @@ freePGconn(PGconn *conn)
2011
2002
/* Note that conn->Pfdebug is not ours to close or free */
2012
2003
if (conn -> last_query )
2013
2004
free (conn -> last_query );
2014
- pg_freeaddrinfo_all (conn -> addrlist_family , conn -> addrlist );
2015
- notify = conn -> notifyHead ;
2016
- while (notify != NULL )
2017
- {
2018
- PGnotify * prev = notify ;
2019
-
2020
- notify = notify -> next ;
2021
- free (prev );
2022
- }
2023
- #ifdef ENABLE_GSS
2024
- {
2025
- OM_uint32 min_s ;
2026
-
2027
- if (conn -> gctx )
2028
- gss_delete_sec_context (& min_s , & conn -> gctx , GSS_C_NO_BUFFER );
2029
- if (conn -> gtarg_nam )
2030
- gss_release_name (& min_s , & conn -> gtarg_nam );
2031
- if (conn -> ginbuf .length )
2032
- gss_release_buffer (& min_s , & conn -> ginbuf );
2033
- if (conn -> goutbuf .length )
2034
- gss_release_buffer (& min_s , & conn -> goutbuf );
2035
- }
2036
- #endif
2037
- #ifdef ENABLE_SSPI
2038
- {
2039
- if (conn -> ginbuf .length )
2040
- free (conn -> ginbuf .value );
2041
-
2042
- if (conn -> sspitarget )
2043
- free (conn -> sspitarget );
2044
-
2045
- if (conn -> sspicred )
2046
- {
2047
- FreeCredentialsHandle (conn -> sspicred );
2048
- free (conn -> sspicred );
2049
- }
2050
- if (conn -> sspictx )
2051
- {
2052
- DeleteSecurityContext (conn -> sspictx );
2053
- free (conn -> sspictx );
2054
- }
2055
- }
2056
- #endif
2057
- pstatus = conn -> pstatus ;
2058
- while (pstatus != NULL )
2059
- {
2060
- pgParameterStatus * prev = pstatus ;
2061
-
2062
- pstatus = pstatus -> next ;
2063
- free (prev );
2064
- }
2065
- if (conn -> lobjfuncs )
2066
- free (conn -> lobjfuncs );
2067
2005
if (conn -> inBuffer )
2068
2006
free (conn -> inBuffer );
2069
2007
if (conn -> outBuffer )
2070
2008
free (conn -> outBuffer );
2071
2009
termPQExpBuffer (& conn -> errorMessage );
2072
2010
termPQExpBuffer (& conn -> workBuffer );
2011
+
2073
2012
free (conn );
2074
2013
2075
2014
#ifdef WIN32
@@ -2081,7 +2020,9 @@ freePGconn(PGconn *conn)
2081
2020
* closePGconn
2082
2021
* - properly close a connection to the backend
2083
2022
*
2084
- * Release all transient state, but NOT the connection parameters.
2023
+ * This should reset or release all transient state, but NOT the connection
2024
+ * parameters. On exit, the PGconn should be in condition to start a fresh
2025
+ * connection with the same parameters (see PQreset()).
2085
2026
*/
2086
2027
static void
2087
2028
closePGconn (PGconn * conn )
@@ -2105,9 +2046,10 @@ closePGconn(PGconn *conn)
2105
2046
}
2106
2047
2107
2048
/*
2108
- * must reset the blocking status so a possible reconnect will work don't
2109
- * call PQsetnonblocking() because it will fail if it's unable to flush
2110
- * the connection.
2049
+ * Must reset the blocking status so a possible reconnect will work.
2050
+ *
2051
+ * Don't call PQsetnonblocking() because it will fail if it's unable to
2052
+ * flush the connection.
2111
2053
*/
2112
2054
conn -> nonblocking = FALSE;
2113
2055
@@ -2135,7 +2077,7 @@ closePGconn(PGconn *conn)
2135
2077
notify = notify -> next ;
2136
2078
free (prev );
2137
2079
}
2138
- conn -> notifyHead = NULL ;
2080
+ conn -> notifyHead = conn -> notifyTail = NULL ;
2139
2081
pstatus = conn -> pstatus ;
2140
2082
while (pstatus != NULL )
2141
2083
{
@@ -2150,6 +2092,41 @@ closePGconn(PGconn *conn)
2150
2092
conn -> lobjfuncs = NULL ;
2151
2093
conn -> inStart = conn -> inCursor = conn -> inEnd = 0 ;
2152
2094
conn -> outCount = 0 ;
2095
+ #ifdef ENABLE_GSS
2096
+ {
2097
+ OM_uint32 min_s ;
2098
+
2099
+ if (conn -> gctx )
2100
+ gss_delete_sec_context (& min_s , & conn -> gctx , GSS_C_NO_BUFFER );
2101
+ if (conn -> gtarg_nam )
2102
+ gss_release_name (& min_s , & conn -> gtarg_nam );
2103
+ if (conn -> ginbuf .length )
2104
+ gss_release_buffer (& min_s , & conn -> ginbuf );
2105
+ if (conn -> goutbuf .length )
2106
+ gss_release_buffer (& min_s , & conn -> goutbuf );
2107
+ }
2108
+ #endif
2109
+ #ifdef ENABLE_SSPI
2110
+ if (conn -> ginbuf .length )
2111
+ free (conn -> ginbuf .value );
2112
+ conn -> ginbuf .length = 0 ;
2113
+ conn -> ginbuf .value = NULL ;
2114
+ if (conn -> sspitarget )
2115
+ free (conn -> sspitarget );
2116
+ conn -> sspitarget = NULL ;
2117
+ if (conn -> sspicred )
2118
+ {
2119
+ FreeCredentialsHandle (conn -> sspicred );
2120
+ free (conn -> sspicred );
2121
+ conn -> sspicred = NULL ;
2122
+ }
2123
+ if (conn -> sspictx )
2124
+ {
2125
+ DeleteSecurityContext (conn -> sspictx );
2126
+ free (conn -> sspictx );
2127
+ conn -> sspictx = NULL ;
2128
+ }
2129
+ #endif
2153
2130
}
2154
2131
2155
2132
/*
0 commit comments