Potential memory leak in contrib/intarray's g_intbig_compress - Mailing list pgsql-hackers

From Matthias van de Meent
Subject Potential memory leak in contrib/intarray's g_intbig_compress
Date
Msg-id CAEze2Wi86=DxErfvf+SCB2UKmU2amKOF60BKuJOX=w-RojRn0A@mail.gmail.com
Whole thread Raw
Responses Re: Potential memory leak in contrib/intarray's g_intbig_compress
List pgsql-hackers
Hi,

My collegue Konstantin (cc-ed) noticed that the GiST code of intarray
may leak memory in certain index operations:

> g_intbig_compress(...):
> [...]
>         ArrayType  *in = DatumGetArrayTypeP(entry->key);
> [...]
>         if (in != DatumGetArrayTypeP(entry->key))
>             pfree(in);

DatumGetArrayTypeP will allocate a new, uncompressed copy if the given
Datum is compressed. So in this code, if entry->key is compressed we'd
allocate two decompressed copies, while only we only deallocate the
first of these two. I believe the attached patch fixes the issue.

It looks like this bug has existed since the code was first committed,
so backpatching would go back to 11 if this is an active issue.

Kind regards,

Matthias van de Meent

Attachment

pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Better help output for pgbench -I init_steps
Next
From: Amit Langote
Date:
Subject: Re: generic plans and "initial" pruning