public inbox for [email protected]  
help / color / mirror / Atom feed
From: Fujii Masao <[email protected]>
To: Ranier Vilela <[email protected]>
Cc: Pg Hackers <[email protected]>
Subject: Re: Avoid resource leak (contrib/postgres_fdw/connection.c)
Date: Tue, 17 Mar 2026 08:07:47 +0900
Message-ID: <CAHGQGwG2iC2LeizHiCezb-D=G6RE-ACXbFVfeAtzXwjnMTveGA@mail.gmail.com> (raw)
In-Reply-To: <CAEudQAprLegxufoi93JuFVkCDmjT5wtGhu3gxT-E1Fg+1DGrag@mail.gmail.com>
References: <CAEudQAprLegxufoi93JuFVkCDmjT5wtGhu3gxT-E1Fg+1DGrag@mail.gmail.com>

On Mon, Mar 16, 2026 at 8:46 PM Ranier Vilela <[email protected]> wrote:
>
> 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.

It seems that postgres_fdw_connection() is expected to be called by
ForeignServerConnectionString() via OidFunctionCall3(),
and to allocate memory (including str.data) in the FDWConnectionContext
memory context created by ForeignServerConnectionString().

After calling postgres_fdw_connection(), ForeignServerConnectionString()
deletes FDWConnectionContext. So it seems to me that any memory
allocated in that context, including str.data, would not leak. No?

Regards,

-- 
Fujii Masao





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], [email protected]
  Subject: Re: Avoid resource leak (contrib/postgres_fdw/connection.c)
  In-Reply-To: <CAHGQGwG2iC2LeizHiCezb-D=G6RE-ACXbFVfeAtzXwjnMTveGA@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