aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2025-02-12 17:11:43 +0900
committerMichael Paquier <michael@paquier.xyz>2025-02-12 17:11:43 +0900
commit5b94e2753439b699b78aacbb53e89bf0e814becc (patch)
treed8b49c88709d46203d39953c45d224febd1c6343
parent1b5841d4615045e48c3a0019e36f91e4e71d0912 (diff)
downloadpostgresql-5b94e2753439b699b78aacbb53e89bf0e814becc.tar.gz
postgresql-5b94e2753439b699b78aacbb53e89bf0e814becc.zip
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
-rw-r--r--src/bin/pg_basebackup/pg_createsubscriber.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c
index faf18ccf131..2d881d54f5b 100644
--- a/src/bin/pg_basebackup/pg_createsubscriber.c
+++ b/src/bin/pg_basebackup/pg_createsubscriber.c
@@ -1130,6 +1130,7 @@ check_and_drop_existing_subscriptions(PGconn *conn,
PQclear(res);
destroyPQExpBuffer(query);
+ PQfreemem(dbname);
}
/*
@@ -1329,7 +1330,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);
@@ -1375,7 +1376,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);
@@ -1614,8 +1615,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);
}
@@ -1638,7 +1639,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);
@@ -1702,10 +1703,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);
@@ -1812,8 +1813,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);
@@ -1856,7 +1857,7 @@ enable_subscription(PGconn *conn, const struct LogicalRepInfo *dbinfo)
PQclear(res);
}
- pg_free(subname);
+ PQfreemem(subname);
destroyPQExpBuffer(str);
}