1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-18 13:44:19 +03:00

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
This commit is contained in:
Michael Paquier 2025-02-12 17:11:43 +09:00
parent 1b5841d461
commit 5b94e27534

View File

@ -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);
}