Content-Length: 347063 | pFad | http://github.com/postgrespro/postgres/commit/16a61884b5956778cae64a5746f4cdd9ae1ae01b

25 Fix memory leaks in libpqwalreceiver · postgrespro/postgres@16a6188 · GitHub
Skip to content

Commit 16a6188

Browse files
committed
Fix memory leaks in libpqwalreceiver
The results of the libpq functions PQescapeIdentifier() and PQescapeLiteral() must be freed explicitly. Also handle errors in these functions better.
1 parent 7e26e02 commit 16a6188

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,17 +304,30 @@ libpqrcv_startstreaming(WalReceiverConn *conn,
304304
{
305305
char *pubnames_str;
306306
List *pubnames;
307+
char *pubnames_literal;
307308

308309
appendStringInfoString(&cmd, " (");
310+
309311
appendStringInfo(&cmd, "proto_version '%u'",
310312
options->proto.logical.proto_version);
313+
311314
pubnames = options->proto.logical.publication_names;
312315
pubnames_str = stringlist_to_identifierstr(conn->streamConn, pubnames);
313-
appendStringInfo(&cmd, ", publication_names %s",
314-
PQescapeLiteral(conn->streamConn, pubnames_str,
315-
strlen(pubnames_str)));
316-
appendStringInfoChar(&cmd, ')');
316+
if (!pubnames_str)
317+
ereport(ERROR,
318+
(errmsg("could not start WAL streaming: %s",
319+
PQerrorMessage(conn->streamConn))));
320+
pubnames_literal = PQescapeLiteral(conn->streamConn, pubnames_str,
321+
strlen(pubnames_str));
322+
if (!pubnames_literal)
323+
ereport(ERROR,
324+
(errmsg("could not start WAL streaming: %s",
325+
PQerrorMessage(conn->streamConn))));
326+
appendStringInfo(&cmd, ", publication_names %s", pubnames_literal);
327+
PQfreemem(pubnames_literal);
317328
pfree(pubnames_str);
329+
330+
appendStringInfoChar(&cmd, ')');
318331
}
319332
else
320333
appendStringInfo(&cmd, " TIMELINE %u",
@@ -736,14 +749,21 @@ stringlist_to_identifierstr(PGconn *conn, List *strings)
736749
foreach (lc, strings)
737750
{
738751
char *val = strVal(lfirst(lc));
752+
char *val_escaped;
739753

740754
if (first)
741755
first = false;
742756
else
743757
appendStringInfoChar(&res, ',');
744758

745-
appendStringInfoString(&res,
746-
PQescapeIdentifier(conn, val, strlen(val)));
759+
val_escaped = PQescapeIdentifier(conn, val, strlen(val));
760+
if (!val_escaped)
761+
{
762+
free(res.data);
763+
return NULL;
764+
}
765+
appendStringInfoString(&res, val_escaped);
766+
PQfreemem(val_escaped);
747767
}
748768

749769
return res.data;

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres/commit/16a61884b5956778cae64a5746f4cdd9ae1ae01b

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy