Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w28mm-0001cm-2C for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Mar 2026 14:19:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w28mk-00ANxr-2E for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Mar 2026 14:19:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w28mk-00ANxj-1H for pgsql-hackers@lists.postgresql.org; Mon, 16 Mar 2026 14:19:11 +0000 Received: from mail-dy1-x132f.google.com ([2607:f8b0:4864:20::132f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w28mi-00000000RB2-1gO3 for pgsql-hackers@postgresql.org; Mon, 16 Mar 2026 14:19:10 +0000 Received: by mail-dy1-x132f.google.com with SMTP id 5a478bee46e88-2bea8a1c040so2561015eec.0 for ; Mon, 16 Mar 2026 07:19:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773670747; cv=none; d=google.com; s=arc-20240605; b=JhbJRxs4BNrTqcXlZvo0rCBIni6EgkXLc26uf8uRwGiyiks47W9WZ6CXZ1tTuoPOCt eVRrdiYJTLwyl3SA5/vJvptar4bpyBauLr4GFnDKU09XBAMyrZE9tZp1r/R4sjrU88TQ +T7PEC9hU9EWcRYezfMoOxr2V/VuWKRGmjXXbpAGbkViz69h3YLCDIgbFJalArxWXNGZ x5nrmHaJsgldaK2o4ppSjFnDFj+J8ebu8qPoyup4eb2WjAGJUDJQ6OZXCwSrSG56UKmn 5URbVC619dPIN8h/eYpwRiC6L/m91HqnDMjcQE4ygBv1nPowV1cqEx2NshUZHCruWQ/W qBMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=eC+H94z8yAVSNcyFJu2HEXW12rikxco3EAelgjJLxM0=; fh=kIGeFeFTNIbN7EmIsZtwNhXU7WDAIjnXz/F5ALIgY6o=; b=XeDRruLNCBZ9i0jtOeMYU1ZvyOV2tUTY5v/7u0M4ASgufdUFIl4bCJuAOUW4zaVUYY 33nCmRxyHtsQUnM7rcM1ThceubpxRReVCEjjZGNWbQTfPu5hDos6IrqOvrZXkbR20IZO e/C6DOO7OYsnhnr4+tLhMPePGeOmWC4NRrlxL2BkitxNFlNkXnztE2hG8AHOvrMTS89g 6Stb8wXQ3aLWhS76S4GXpyZ0u21zwvqMvauBemeRYWanB1Oiwcza7bxoso5tQmH4R1Vo eXWRcsyhWM4F/E6S9N3SAZpW5ussJpe8KW0FtHrxGevtV8J4HcZwqsClMQ8KSDtQfeaK gWKw==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773670747; x=1774275547; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=eC+H94z8yAVSNcyFJu2HEXW12rikxco3EAelgjJLxM0=; b=PMLSfmXfhOteJOc+TWfLSk3EmCglneM8aR0yDz5cPKhgW+v6ExXTCJFNAkLnQ4V6jY f5xsAwr3aZCYkZS6+2ka5PJaIKr+0Vm8zMUuh2XdkdbXkO7QEmuqy4Xoax54HVOBIuXe N+CAyWKl7PYyQ4smBs8l/d8mWLYhDiHQOKwVPp5OUyoa/odS1AL+auzfUvkZcRRDGJTE Y5RkcpQG3dgQPt1aKMs8lSUABBnCeMjh2kacU6rZG8vBGjgarR3MdX8M8D9MHMnYSDrN B2dJACoQBpwcX31LLU/oe8SG8ikuThRzqTReDW7COIcagU3NBJG7K8IuOiIUca7IxW9H F5iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773670747; x=1774275547; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=eC+H94z8yAVSNcyFJu2HEXW12rikxco3EAelgjJLxM0=; b=YVII60VfEWcXerslJgTzoU8Arqt3mJnzJ8I8u06oCwP4/9l/DB3UA6x3/TKJG+UFgi UWY00ZCq7e/Kf6QjCQRnMD7GWeS3A7BEl6DRqwmSaQVTd5+AMVFds5chSTuIbI4v3Dib JZUX66RFTLCmsgma6ei7W9KYQNwIuZZEZLiBQknUdUumwBrbk80J0+67p6DRQYsUsrOm /f+S9YlJyk3mtLm3Q4JdoyznLbBaL+rxiChPgJqn5affjyduFP4yJ3nX/9YqhVA9V6/I KkkTL6KIgGFs+fNasa9wZjC9SNyux+G5vGG96zNTbZJwzM4z6PyFIGhIdkQHLmXYEfV/ uGzw== X-Gm-Message-State: AOJu0YxdCVVP4vuy+9osgzyHb/8rqdDyP99pKtO08iUP2bpiow7mTyLl X7qpsfcemmeauO/6PNnNpDdsiu8LyHNyyOoYXnL6kmJjplIFvpm6DNCwhEyWBh/FoXNnDCedfhC Ra+8017/VG6lBBnKVmM320WPcqtVAh6A= X-Gm-Gg: ATEYQzyci9j0Ji8iW+dlNGgcFbj4ppx+09OYpTayANPqT9nOyhkNnvcZPxzCsO/eV7D BvBgNOVQGdjkbZlkQuIe6F26sSb69MuoryOT9jv1j06aDFEQpvKMnY7TCy89iktdKPAQnenRz40 qy+XqWt9eRI1NnQ4tRjD8vz0b+eNg5sbrIMFbW866CETzn3qz+dmsarlBBu9gmg8a8/zLLbC3of s5P5h6Th7YaIn3sXdLM5XD87q7zipts2deWP7W/GBYKsvEmAuNBOEqcWPL9Hguh+ReT4zBjoyDl 0JzMoKE= X-Received: by 2002:a05:693c:6086:b0:2c0:c415:cfd0 with SMTP id 5a478bee46e88-2c0c415d4aamr1358600eec.15.1773670746479; Mon, 16 Mar 2026 07:19:06 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ranier Vilela Date: Mon, 16 Mar 2026 11:18:54 -0300 X-Gm-Features: AaiRm53MEO853Eb7z39gebIpC0liz8oWI1wVfBIlu2L6xgP25-5LAaT1mf_gsBU Message-ID: Subject: Re: Avoid resource leak (contrib/postgres_fdw/connection.c) To: Matheus Alcantara Cc: Pg Hackers Content-Type: multipart/alternative; boundary="000000000000caea89064d24e673" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000caea89064d24e673 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi. Em seg., 16 de mar. de 2026 =C3=A0s 11:16, Matheus Alcantara < matheusssilv97@gmail.com> escreveu: > 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. > Thanks for taking a look. best regards, Ranier Vilela --000000000000caea89064d24e673 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi.

Em seg., 16 de mar. de 2026 = =C3=A0s 11:16, Matheus Alcantara <matheusssilv97@gmail.com> escreveu:
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.
Thanks for taking a look.

best regards,
Ranier Vilela
--000000000000caea89064d24e673--