Small memory fixes for pg_createsubcriber

Ranier Vilela <ranier.vf@gmail.com>

From: Ranier Vilela <ranier.vf@gmail.com>
To: Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2025-02-10T16:31:20Z
Lists: pgsql-hackers

Attachments

Hi.

Per Coverity.

Coverity has some reports about pg_createsubcriber.

CID 1591322: (#1 of 1): Resource leak (RESOURCE_LEAK)
10. leaked_storage: Variable dbname going out of scope leaks the storage it
points to.

Additionally there are several calls that are out of the ordinary,
according to the Postgres API.

According to the documentation:
libpq-exec <https://www.postgresql.org/docs/current/libpq-exec.html>

The correct function to free memory when using PQescapeLiteral and
PQescapeIdentifier would be PQfreemem.

Trivial fixes attached.

best regards,
Ranier Vilela

Commits

  1. pg_upgrade: Fix inconsistency in memory freeing

  2. pg_amcheck: Fix inconsistency in memory freeing

  3. Fix some inconsistencies with memory freeing in pg_createsubscriber

  4. Drop pre-existing subscriptions from the converted subscriber.