postgres.git / summary / log / commit / refs
commit ff6d9cfcb17e48c313aefe8fc65cdaeacd8766bf
Author: Michael Paquier <michael@paquier.xyz>
Date: Wed Feb 12 08:11:47 2025 +0000
First released in: 18.0, 17.4
Fix some inconsistencies with memory freeing in pg_createsubscriber
The correct function documented to free the memory allocated for the
result returned by PQescapeIdentifier() and PQescapeLiteral() is
PQfreemem(). pg_createsubscriber.c relied on pg_free() instead, which
is not incorrect as both do a free() internally, but inconsistent with
the documentation.
While on it, this commit fixes a small memory leak introduced by
4867f8a555ce, as the code of pg_createsubscriber makes this effort.
Author: Ranier Vilela
Reviewed-by: Euler Taveira
Discussion: https://postgr.es/m/CAEudQAp=AW5dJXrGLbC_aZg_9nOo=42W7uLDRONFQE-gcgnkgQ@mail.gmail.com
Backpatch-through: 17
src/bin/pg_basebackup/pg_createsubscriber.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c
index 6b793931f3e..677c0cd0843 100644
--- a/src/bin/pg_basebackup/pg_createsubscriber.c
+++ b/src/bin/pg_basebackup/pg_createsubscriber.c
@@ -1131,6 +1131,7 @@ check_and_drop_existing_subscriptions(PGconn *conn,
PQclear(res);
destroyPQExpBuffer(query);
+ PQfreemem(dbname);
}
/*
@@ -1330,7 +1331,7 @@ create_logical_replication_slot(PGconn *conn, struct LogicalRepInfo *dbinfo)
"SELECT lsn FROM pg_catalog.pg_create_logical_replication_slot(%s, 'pgoutput', false, false, false)",
slot_name_esc);
- pg_free(slot_name_esc);
+ PQfreemem(slot_name_esc);
pg_log_debug("command is: %s", str->data);
@@ -1376,7 +1377,7 @@ drop_replication_slot(PGconn *conn, struct LogicalRepInfo *dbinfo,
appendPQExpBuffer(str, "SELECT pg_catalog.pg_drop_replication_slot(%s)", slot_name_esc);
- pg_free(slot_name_esc);
+ PQfreemem(slot_name_esc);
pg_log_debug("command is: %s", str->data);
@@ -1615,8 +1616,8 @@ create_publication(PGconn *conn, struct LogicalRepInfo *dbinfo)
/* For cleanup purposes */
dbinfo->made_publication = true;
- pg_free(ipubname_esc);
- pg_free(spubname_esc);
+ PQfreemem(ipubname_esc);
+ PQfreemem(spubname_esc);
destroyPQExpBuffer(str);
}
@@ -1639,7 +1640,7 @@ drop_publication(PGconn *conn, struct LogicalRepInfo *dbinfo)
appendPQExpBuffer(str, "DROP PUBLICATION %s", pubname_esc);
- pg_free(pubname_esc);
+ PQfreemem(pubname_esc);
pg_log_debug("command is: %s", str->data);
@@ -1703,10 +1704,10 @@ create_subscription(PGconn *conn, const struct LogicalRepInfo *dbinfo)
"slot_name = %s, copy_data = false)",
subname_esc, pubconninfo_esc, pubname_esc, replslotname_esc);
- pg_free(pubname_esc);
- pg_free(subname_esc);
- pg_free(pubconninfo_esc);
- pg_free(replslotname_esc);
+ PQfreemem(pubname_esc);
+ PQfreemem(subname_esc);
+ PQfreemem(pubconninfo_esc);
+ PQfreemem(replslotname_esc);
pg_log_debug("command is: %s", str->data);
@@ -1813,8 +1814,8 @@ set_replication_progress(PGconn *conn, const struct LogicalRepInfo *dbinfo, cons
PQclear(res);
}
- pg_free(subname);
- pg_free(dbname);
+ PQfreemem(subname);
+ PQfreemem(dbname);
pg_free(originname);
pg_free(lsnstr);
destroyPQExpBuffer(str);
@@ -1857,7 +1858,7 @@ enable_subscription(PGconn *conn, const struct LogicalRepInfo *dbinfo)
PQclear(res);
}
- pg_free(subname);
+ PQfreemem(subname);
destroyPQExpBuffer(str);
}
[parent: fa761d9c7137]