Re: Avoid resource leak (contrib/postgres_fdw/connection.c)

From: Matheus Alcantara <matheusssilv97(at)gmail(dot)com>
To: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Avoid resource leak (contrib/postgres_fdw/connection.c)
Date: 2026-03-16 14:16:30
Message-ID: a984fb94-0694-4b70-9fbb-8562acb4e8f1@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 16/03/26 08:45, Ranier Vilela 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.
>
> patch attached.
>

Hi,

Thanks for the patch, it looks correct to me. I've searched for this
pattern `PG_RETURN_TEXT_P(cstring_to_text(.*.data` in other places and
I've just found on postgres_fdw/connection.c

I've also search for other cases of `return cstring_to_text(...)`
usages and I didn't found anything that seems suspicious.

Tests are also passing.

--
Matheus Alcantara
EDB: https://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ranier Vilela 2026-03-16 14:18:54 Re: Avoid resource leak (contrib/postgres_fdw/connection.c)
Previous Message Amit Langote 2026-03-16 14:03:41 Re: Eliminating SPI / SQL from some RI triggers - take 3