1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-21 15:54:08 +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:47 +09:00
parent fa761d9c71
commit ff6d9cfcb1

View File

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