postgres.git / summary / log / commit / refs
commit ba986b7bc5cf2cc9f586e553f78ab9b2b199fac2
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Fri Mar 19 02:21:58 2021 +0000
First released in: 14.0, 10.17, 11.12, 12.7, 13.3
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
src/backend/replication/libpqwalreceiver/libpqwalreceiver.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
index fb8118f8af9..ae8af6aa204 100644
--- a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
+++ b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
@@ -244,9 +244,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);
}
[parent: 5058e95a6ef9]