Potential memory leak in contrib/intarray's g_intbig_compress
Matthias van de Meent <boekewurm+postgres@gmail.com>
From: Matthias van de Meent <boekewurm+postgres@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Cc: Konstantin Knizhnik <knizhnik@garret.ru>
Date: 2023-07-13T12:02:36Z
Lists: pgsql-hackers
Attachments
- 0001-Fix-memory-leak-in-g_intbig_compress.patch (application/octet-stream) patch 0001
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
Commits
-
Remove unnecessary pfree() in g_intbig_compress().
- 9f70f6d4c5bc 11.21 landed
- 8d8f3714988b 12.16 landed
- 7fffcc2ee910 13.12 landed
- a6991f763df8 14.9 landed
- 5cb4619896d8 15.4 landed
- e27f3f52c289 16.0 landed
- 8aac9759bb85 17.0 landed