diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-03-18 22:21:58 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-03-18 22:21:58 -0400 |
commit | 4eca51d4464133e6f4cd923355c6dd971d9c27d3 (patch) | |
tree | 11a79a9020cbc2a497a5d03b03463a5365c2560a /src | |
parent | fc552f8680a79d602beae230615ffe8ed236cc43 (diff) | |
download | postgresql-4eca51d4464133e6f4cd923355c6dd971d9c27d3.tar.gz postgresql-4eca51d4464133e6f4cd923355c6dd971d9c27d3.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/replication/libpqwalreceiver/libpqwalreceiver.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c index a951568af9c..dab3152e6bc 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); } |