public inbox for [email protected]
help / color / mirror / Atom feedFrom: Ranier Vilela <[email protected]>
To: Pg Hackers <[email protected]>
Subject: Avoid resource leak (contrib/postgres_fdw/connection.c)
Date: Mon, 16 Mar 2026 08:45:49 -0300
Message-ID: <CAEudQAprLegxufoi93JuFVkCDmjT5wtGhu3gxT-E1Fg+1DGrag@mail.gmail.com> (raw)
Hi.
Per Coverity.
CID 1645716: (#1 of 1): Resource leak (RESOURCE_LEAK)
8. leaked_storage: Variable str going out of scope leaks the storage
str.data points to.
The function *postgres_fdw_connection* leaks the contents of
var str.data
Once that function *cstring_to_text* palloc the contents
must be necessary to free the var str.data.
patch attached.
best regards,
Ranier Vilelas
Attachments:
[application/octet-stream] avoid-resource-leak-postgres_fdw-connection.patch (827B, 3-avoid-resource-leak-postgres_fdw-connection.patch)
download | inline diff:
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 7e2b822d16..87f3e3727f 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -2355,6 +2355,7 @@ postgres_fdw_connection(PG_FUNCTION_ARGS)
ForeignServer *server = GetForeignServer(serverid);
UserMapping *user = GetUserMapping(userid, serverid);
StringInfoData str;
+ text *result;
const char **keywords;
const char **values;
char *appname;
@@ -2371,12 +2372,15 @@ postgres_fdw_connection(PG_FUNCTION_ARGS)
appendEscapedValue(&str, values[i]);
sep = " ";
}
+ result = cstring_to_text(str.data);
if (appname != NULL)
pfree(appname);
pfree(keywords);
pfree(values);
- PG_RETURN_TEXT_P(cstring_to_text(str.data));
+ pfree(str.data);
+
+ PG_RETURN_TEXT_P(result);
}
/*
view thread (5+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: Avoid resource leak (contrib/postgres_fdw/connection.c)
In-Reply-To: <CAEudQAprLegxufoi93JuFVkCDmjT5wtGhu3gxT-E1Fg+1DGrag@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox