Skip to content

Commit c1daadf

Browse files
authored
Per valgrind, fix some memory leaks. (#799)
* Per valgrind, fix some memory leaks. We would be using PQfreemem on a PQExpBuffer, where it's expected to be using destroyPQExpBuffer instead. Also we were short of a call to finish the connection to the monitor notification client when exiting from the service keeper process, although adding this clean-up doesn't seem to impact the valgrind reports.
1 parent ec8f8d9 commit c1daadf

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/bin/pg_autoctl/pgsql.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,8 +1640,8 @@ pgsql_replication_slot_create_and_drop(PGSQL *pgsql, NodeAddressArray *nodeArray
16401640
if (!BuildNodesArrayValues(nodeArray, &sqlParams, values))
16411641
{
16421642
/* errors have already been logged */
1643-
PQfreemem(query);
1644-
PQfreemem(values);
1643+
destroyPQExpBuffer(query);
1644+
destroyPQExpBuffer(values);
16451645

16461646
return false;
16471647
}
@@ -1658,8 +1658,8 @@ pgsql_replication_slot_create_and_drop(PGSQL *pgsql, NodeAddressArray *nodeArray
16581658
&context,
16591659
parseReplicationSlotMaintain);
16601660

1661-
PQfreemem(query);
1662-
PQfreemem(values);
1661+
destroyPQExpBuffer(query);
1662+
destroyPQExpBuffer(values);
16631663

16641664
return success;
16651665
}
@@ -1717,8 +1717,8 @@ pgsql_replication_slot_maintain(PGSQL *pgsql, NodeAddressArray *nodeArray)
17171717
if (!BuildNodesArrayValues(nodeArray, &sqlParams, values))
17181718
{
17191719
/* errors have already been logged */
1720-
PQfreemem(query);
1721-
PQfreemem(values);
1720+
destroyPQExpBuffer(query);
1721+
destroyPQExpBuffer(values);
17221722

17231723
return false;
17241724
}
@@ -1735,8 +1735,8 @@ pgsql_replication_slot_maintain(PGSQL *pgsql, NodeAddressArray *nodeArray)
17351735
&context,
17361736
parseReplicationSlotMaintain);
17371737

1738-
PQfreemem(query);
1739-
PQfreemem(values);
1738+
destroyPQExpBuffer(query);
1739+
destroyPQExpBuffer(values);
17401740

17411741
return success;
17421742
}

src/bin/pg_autoctl/service_keeper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ keeper_node_active_loop(Keeper *keeper, pid_t start_pid)
661661

662662
/* One last check that we do not have any connections open */
663663
pgsql_finish(&(keeper->monitor.pgsql));
664+
pgsql_finish(&(monitor->notificationClient));
664665

665666
if (nodeHasBeenDroppedFromTheMonitor)
666667
{

0 commit comments

Comments
 (0)