Fix memory leak in connection string validation.
authorJeff Davis <[email protected]>
Sat, 13 Jan 2024 05:38:16 +0000 (21:38 -0800)
committerJeff Davis <[email protected]>
Sat, 13 Jan 2024 05:40:23 +0000 (21:40 -0800)
Introduced in commit c3afe8cf5a.

Discussion: https://postgr.es/m/066a65233d3cb4ea27a9e0778d2f1d0dc764b222[email protected]
Reviewed-by: Nathan Bossart, Tom Lane
Backpatch-through: 16

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

index ead30f87c96c741b30d895637930cf45f603fc59..201c36cb220606bdee76c275ef98ee153dffe66e 100644 (file)
@@ -284,10 +284,15 @@ libpqrcv_check_conninfo(const char *conninfo, bool must_use_password)
        }
 
        if (!uses_password)
+       {
+           /* malloc'd, so we must free it explicitly */
+           PQconninfoFree(opts);
+
            ereport(ERROR,
                    (errcode(ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED),
                     errmsg("password is required"),
                     errdetail("Non-superusers must provide a password in the connection string.")));
+       }
    }
 
    PQconninfoFree(opts);