Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16a6188

Browse files
committed
Fix memory leaks in libpqwalreceiver
The results of the libpq functions PQescapeIdentifier() andPQescapeLiteral() must be freed explicitly. Also handle errors in thesefunctions better.
1 parent7e26e02 commit16a6188

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+
returnNULL;
764+
}
765+
appendStringInfoString(&res,val_escaped);
766+
PQfreemem(val_escaped);
747767
}
748768

749769
returnres.data;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp