Thread: Avoid redudant initialization and possible memory leak (src/backend/parser/parse_relation.c)

Hi,

The commit: Revert SQL/JSON features

Left a little oversight.
I believe it will be properly corrected when it is applied again.
However, for Postgres 15 this may can cause a small memory leak.

Attached a fix patch.

regards,
Ranier Vilela
Attachment
On Tue, Sep 13, 2022 at 10:21:22AM -0300, Ranier Vilela wrote:
> Hi,
>
> The commit: Revert SQL/JSON features
> https://github.com/postgres/postgres/commit/2f2b18bd3f554e96a8cc885b177211be12288e4a
>
> Left a little oversight.
> I believe it will be properly corrected when it is applied again.
> However, for Postgres 15 this may can cause a small memory leak.

It's not a memory leak, the chunk will be freed eventually when the owning
memory context is reset, but I agree that one of the two identical
initializations should be removed.



On 2022-Sep-13, Ranier Vilela wrote:

> However, for Postgres 15 this may can cause a small memory leak.

What memory leak?  There's no leak here.

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
Bob [Floyd] used to say that he was planning to get a Ph.D. by the "green
stamp method," namely by saving envelopes addressed to him as 'Dr. Floyd'.
After collecting 500 such letters, he mused, a university somewhere in
Arizona would probably grant him a degree.              (Don Knuth)



Em ter., 13 de set. de 2022 às 11:09, Alvaro Herrera <alvherre@alvh.no-ip.org> escreveu:
On 2022-Sep-13, Ranier Vilela wrote:

> However, for Postgres 15 this may can cause a small memory leak.

What memory leak?  There's no leak here.
Yeah, as per Julien's answer, there is really no memory leak, but just unnecessary double execution of pstrdup.
But for Postgres 15, I believe it's worth avoiding this, because it's wasted cycles.
For Postgres 16, I believe this will be fixed as well, but for robustness, better fix soon, IMO.

regards,
Ranier Vilela
On 2022-Sep-13, Ranier Vilela wrote:

> Yeah, as per Julien's answer, there is really no memory leak, but just
> unnecessary double execution of pstrdup.
> But for Postgres 15, I believe it's worth avoiding this, because it's
> wasted cycles.

Yeah, this is a merge mistake.  Fix applied, thanks.

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/