Skip to content

Commit 273b29d

Browse files
committed
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.
1 parent d9f38c7 commit 273b29d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/bin/pg_basebackup/streamutil.c

+22
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,17 @@ RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli,
251251
{
252252
fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
253253
progname, "IDENTIFY_SYSTEM", PQerrorMessage(conn));
254+
255+
PQclear(res);
254256
return false;
255257
}
256258
if (PQntuples(res) != 1 || PQnfields(res) < 3)
257259
{
258260
fprintf(stderr,
259261
_("%s: could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields\n"),
260262
progname, PQntuples(res), PQnfields(res), 1, 3);
263+
264+
PQclear(res);
261265
return false;
262266
}
263267

@@ -277,6 +281,8 @@ RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli,
277281
fprintf(stderr,
278282
_("%s: could not parse transaction log location \"%s\"\n"),
279283
progname, PQgetvalue(res, 0, 2));
284+
285+
PQclear(res);
280286
return false;
281287
}
282288
*startpos = ((uint64) hi) << 32 | lo;
@@ -331,6 +337,9 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
331337
{
332338
fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
333339
progname, query->data, PQerrorMessage(conn));
340+
341+
destroyPQExpBuffer(query);
342+
PQclear(res);
334343
return false;
335344
}
336345

@@ -340,6 +349,9 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
340349
_("%s: could not create replication slot \"%s\": got %d rows and %d fields, expected %d rows and %d fields\n"),
341350
progname, slot_name,
342351
PQntuples(res), PQnfields(res), 1, 4);
352+
353+
destroyPQExpBuffer(query);
354+
PQclear(res);
343355
return false;
344356
}
345357

@@ -353,11 +365,15 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
353365
fprintf(stderr,
354366
_("%s: could not parse transaction log location \"%s\"\n"),
355367
progname, PQgetvalue(res, 0, 1));
368+
369+
destroyPQExpBuffer(query);
370+
PQclear(res);
356371
return false;
357372
}
358373
*startpos = ((uint64) hi) << 32 | lo;
359374
}
360375

376+
destroyPQExpBuffer(query);
361377
PQclear(res);
362378
return true;
363379
}
@@ -384,6 +400,9 @@ DropReplicationSlot(PGconn *conn, const char *slot_name)
384400
{
385401
fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
386402
progname, query->data, PQerrorMessage(conn));
403+
404+
destroyPQExpBuffer(query);
405+
PQclear(res);
387406
return false;
388407
}
389408

@@ -393,6 +412,9 @@ DropReplicationSlot(PGconn *conn, const char *slot_name)
393412
_("%s: could not drop replication slot \"%s\": got %d rows and %d fields, expected %d rows and %d fields\n"),
394413
progname, slot_name,
395414
PQntuples(res), PQnfields(res), 0, 0);
415+
416+
destroyPQExpBuffer(query);
417+
PQclear(res);
396418
return false;
397419
}
398420

0 commit comments

Comments
 (0)