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
This commit is contained in:
Tom Lane 2021-03-18 22:21:58 -04:00
parent 642b0b69b0
commit 12354839e8
1 changed files with 7 additions and 1 deletions

View File

@ -246,9 +246,15 @@ libpqrcv_check_conninfo(const char *conninfo)
opts = PQconninfoParse(conninfo, &err);
if (opts == NULL)
{
/* The error string is malloc'd, so we must free it explicitly */
char *errcopy = err ? pstrdup(err) : "out of memory";
PQfreemem(err);
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("invalid connection string syntax: %s", err)));
errmsg("invalid connection string syntax: %s", errcopy)));
}
PQconninfoFree(opts);
}