Skip to content

Commit 9bacdf9

Browse files
committed
Don't leak malloc'd error string in libpqrcv_check_conninfo().
We leaked the error report from PQconninfoParse, when there was one. It seems unlikely that real usage patterns would repeat the failure often enough to create serious bloat, but let's back-patch anyway to keep the code similar in all branches. Found via valgrind testing. Back-patch to v10 where this code was added. Discussion: https://postgr.es/m/[email protected]
1 parent 377b7a8 commit 9bacdf9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,15 @@ libpqrcv_check_conninfo(const char *conninfo)
246246

247247
opts = PQconninfoParse(conninfo, &err);
248248
if (opts == NULL)
249+
{
250+
/* The error string is malloc'd, so we must free it explicitly */
251+
char *errcopy = err ? pstrdup(err) : "out of memory";
252+
253+
PQfreemem(err);
249254
ereport(ERROR,
250255
(errcode(ERRCODE_SYNTAX_ERROR),
251-
errmsg("invalid connection string syntax: %s", err)));
256+
errmsg("invalid connection string syntax: %s", errcopy)));
257+
}
252258

253259
PQconninfoFree(opts);
254260
}

0 commit comments

Comments
 (0)