Re: Fix memory leak in gist_page_items() of pageinspect
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
To: Chao Li <li.evan.chao@gmail.com>
Cc: Postgres hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-12-12T09:00:08Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Use relation_close() more consistently in contrib/
- 8b9b93e39b10 19 (unreleased) landed
-
Use table/index_close() more consistently
- 9d0f7996e58c 19 (unreleased) landed
-
pageinspect: use index_close() for GiST index relation
- 171198ff2a57 19 (unreleased) landed
Hi, On Fri, Dec 12, 2025 at 04:50:09PM +0800, Chao Li wrote: > Hi Hackers, > > While reading the code of pageinspect, I just found a memory leak > in gist_page_items(): > > ``` > values[4] = CStringGetTextDatum(buf.data); > nulls[4] = false; > ``` > > where CStringGetTextDatum() has made a copy of buf.data and assigned to > value[4], however buf.data is never free-ed. I did not look in details but I think that we should be in a short lived memory context here so we generally prefer to avoid using pfree for those cases. > This leak is inside a > per-tuple loop, thus it should be fixed. That might be a valid reason though. Do you have an idea of the "leak" size based on the number of tuples? Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com