Skip to content

Commit 20f11ca

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/3816764.1616104288@sss.pgh.pa.us
1 parent 26a3ae0 commit 20f11ca

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,15 @@ libpqrcv_check_conninfo(const char *conninfo)
248248

249249
opts = PQconninfoParse(conninfo, &err);
250250
if (opts == NULL)
251+
{
252+
/* The error string is malloc'd, so we must free it explicitly */
253+
char *errcopy = err ? pstrdup(err) : "out of memory";
254+
255+
PQfreemem(err);
251256
ereport(ERROR,
252257
(errcode(ERRCODE_SYNTAX_ERROR),
253-
errmsg("invalid connection string syntax: %s", err)));
258+
errmsg("invalid connection string syntax: %s", errcopy)));
259+
}
254260

255261
PQconninfoFree(opts);
256262
}

0 commit comments

Comments
 (0)