From 273b29dbe96b1584dd66615cf8dc83e7e6ae7386 Mon Sep 17 00:00:00 2001 From: Stephen Frost <sfrost@snowman.net> Date: Mon, 6 Oct 2014 11:18:13 -0400 Subject: [PATCH] Clean up Create/DropReplicationSlot query buffer CreateReplicationSlot() and DropReplicationSlot() were not cleaning up the query buffer in some cases (mostly error conditions) which meant a small leak. Not generally an issue as the error case would result in an immediate exit, but not difficult to fix either and reduces the number of false positives from code analyzers. In passing, also add appropriate PQclear() calls to RunIdentifySystem(). Pointed out by Coverity. --- src/bin/pg_basebackup/streamutil.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c index 2f4bac95508..d3694dab38e 100644 --- a/src/bin/pg_basebackup/streamutil.c +++ b/src/bin/pg_basebackup/streamutil.c @@ -251,6 +251,8 @@ RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli, { fprintf(stderr, _("%s: could not send replication command \"%s\": %s"), progname, "IDENTIFY_SYSTEM", PQerrorMessage(conn)); + + PQclear(res); return false; } if (PQntuples(res) != 1 || PQnfields(res) < 3) @@ -258,6 +260,8 @@ RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli, fprintf(stderr, _("%s: could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields\n"), progname, PQntuples(res), PQnfields(res), 1, 3); + + PQclear(res); return false; } @@ -277,6 +281,8 @@ RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli, fprintf(stderr, _("%s: could not parse transaction log location \"%s\"\n"), progname, PQgetvalue(res, 0, 2)); + + PQclear(res); return false; } *startpos = ((uint64) hi) << 32 | lo; @@ -331,6 +337,9 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin, { fprintf(stderr, _("%s: could not send replication command \"%s\": %s"), progname, query->data, PQerrorMessage(conn)); + + destroyPQExpBuffer(query); + PQclear(res); return false; } @@ -340,6 +349,9 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin, _("%s: could not create replication slot \"%s\": got %d rows and %d fields, expected %d rows and %d fields\n"), progname, slot_name, PQntuples(res), PQnfields(res), 1, 4); + + destroyPQExpBuffer(query); + PQclear(res); return false; } @@ -353,11 +365,15 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin, fprintf(stderr, _("%s: could not parse transaction log location \"%s\"\n"), progname, PQgetvalue(res, 0, 1)); + + destroyPQExpBuffer(query); + PQclear(res); return false; } *startpos = ((uint64) hi) << 32 | lo; } + destroyPQExpBuffer(query); PQclear(res); return true; } @@ -384,6 +400,9 @@ DropReplicationSlot(PGconn *conn, const char *slot_name) { fprintf(stderr, _("%s: could not send replication command \"%s\": %s"), progname, query->data, PQerrorMessage(conn)); + + destroyPQExpBuffer(query); + PQclear(res); return false; } @@ -393,6 +412,9 @@ DropReplicationSlot(PGconn *conn, const char *slot_name) _("%s: could not drop replication slot \"%s\": got %d rows and %d fields, expected %d rows and %d fields\n"), progname, slot_name, PQntuples(res), PQnfields(res), 0, 0); + + destroyPQExpBuffer(query); + PQclear(res); return false; } -- GitLab