mirror of
https://github.com/postgres/postgres.git
synced 2025-08-30 06:01:21 +03:00
libpq: Add pqReleaseConnHosts function
In a follow up commit we'll need to free this connhost field in a function defined in fe-cancel.c, so here we extract the logic to a dedicated extern function. Author: Jelte Fennema-Nio <jelte.fennema@microsoft.com> Discussion: https://postgr.es/m/AM5PR83MB0178D3B31CA1B6EC4A8ECC42F7529@AM5PR83MB0178.EURPRD83.prod.outlook.com
This commit is contained in:
@@ -4349,19 +4349,7 @@ freePGconn(PGconn *conn)
|
|||||||
free(conn->events[i].name);
|
free(conn->events[i].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clean up pg_conn_host structures */
|
pqReleaseConnHosts(conn);
|
||||||
for (int i = 0; i < conn->nconnhost; ++i)
|
|
||||||
{
|
|
||||||
free(conn->connhost[i].host);
|
|
||||||
free(conn->connhost[i].hostaddr);
|
|
||||||
free(conn->connhost[i].port);
|
|
||||||
if (conn->connhost[i].password != NULL)
|
|
||||||
{
|
|
||||||
explicit_bzero(conn->connhost[i].password, strlen(conn->connhost[i].password));
|
|
||||||
free(conn->connhost[i].password);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(conn->connhost);
|
|
||||||
|
|
||||||
free(conn->client_encoding_initial);
|
free(conn->client_encoding_initial);
|
||||||
free(conn->events);
|
free(conn->events);
|
||||||
@@ -4423,6 +4411,31 @@ freePGconn(PGconn *conn)
|
|||||||
free(conn);
|
free(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pqReleaseConnHosts
|
||||||
|
* - Free the host list in the PGconn.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
pqReleaseConnHosts(PGconn *conn)
|
||||||
|
{
|
||||||
|
if (conn->connhost)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < conn->nconnhost; ++i)
|
||||||
|
{
|
||||||
|
free(conn->connhost[i].host);
|
||||||
|
free(conn->connhost[i].hostaddr);
|
||||||
|
free(conn->connhost[i].port);
|
||||||
|
if (conn->connhost[i].password != NULL)
|
||||||
|
{
|
||||||
|
explicit_bzero(conn->connhost[i].password,
|
||||||
|
strlen(conn->connhost[i].password));
|
||||||
|
free(conn->connhost[i].password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(conn->connhost);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* store_conn_addrinfo
|
* store_conn_addrinfo
|
||||||
* - copy addrinfo to PGconn object
|
* - copy addrinfo to PGconn object
|
||||||
|
@@ -678,6 +678,7 @@ extern void pqDropConnection(PGconn *conn, bool flushInput);
|
|||||||
#if defined(WIN32) && defined(SIO_KEEPALIVE_VALS)
|
#if defined(WIN32) && defined(SIO_KEEPALIVE_VALS)
|
||||||
extern int pqSetKeepalivesWin32(pgsocket sock, int idle, int interval);
|
extern int pqSetKeepalivesWin32(pgsocket sock, int idle, int interval);
|
||||||
#endif
|
#endif
|
||||||
|
extern void pqReleaseConnHosts(PGconn *conn);
|
||||||
extern int pqPacketSend(PGconn *conn, char pack_type,
|
extern int pqPacketSend(PGconn *conn, char pack_type,
|
||||||
const void *buf, size_t buf_len);
|
const void *buf, size_t buf_len);
|
||||||
extern bool pqGetHomeDirectory(char *buf, int bufsize);
|
extern bool pqGetHomeDirectory(char *buf, int bufsize);
|
||||||
|
Reference in New Issue
Block a user