summaryrefslogtreecommitdiff
path: root/src/interfaces
diff options
context:
space:
mode:
authorAlvaro Herrera2024-02-04 15:19:20 +0000
committerAlvaro Herrera2024-02-04 15:19:20 +0000
commit53747f722228d2cd4d7054c4d509b27dc89306ae (patch)
treefd979a09b056772ff53f42aea797521d6e901df1 /src/interfaces
parentc717525035d36e10d27ca045887bbfcc57e98e9e (diff)
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
Diffstat (limited to 'src/interfaces')
-rw-r--r--src/interfaces/libpq/fe-connect.c39
-rw-r--r--src/interfaces/libpq/libpq-int.h1
2 files changed, 27 insertions, 13 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index c0dea144a00..5add6f4ebb3 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -4349,19 +4349,7 @@ freePGconn(PGconn *conn)
free(conn->events[i].name);
}
- /* clean up pg_conn_host structures */
- 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);
+ pqReleaseConnHosts(conn);
free(conn->client_encoding_initial);
free(conn->events);
@@ -4424,6 +4412,31 @@ freePGconn(PGconn *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
* - copy addrinfo to PGconn object
*
diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h
index ff8e0dce776..5ac50fe20cb 100644
--- a/src/interfaces/libpq/libpq-int.h
+++ b/src/interfaces/libpq/libpq-int.h
@@ -678,6 +678,7 @@ extern void pqDropConnection(PGconn *conn, bool flushInput);
#if defined(WIN32) && defined(SIO_KEEPALIVE_VALS)
extern int pqSetKeepalivesWin32(pgsocket sock, int idle, int interval);
#endif
+extern void pqReleaseConnHosts(PGconn *conn);
extern int pqPacketSend(PGconn *conn, char pack_type,
const void *buf, size_t buf_len);
extern bool pqGetHomeDirectory(char *buf, int bufsize);