Re: Fix memory leak in gist_page_items() of pageinspect

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fix memory leak in gist_page_items() of pageinspect
Date: 2025-12-12 09:00:08
Message-ID: aTvZmGOtONtim1lG@ip-10-97-1-34.eu-west-3.compute.internal
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nazir Bilal Yavuz 2025-12-12 09:18:09 Re: [PATCH] Fix severe performance regression with gettext 0.20+ on Windows
Previous Message Heikki Linnakangas 2025-12-12 08:51:25 Re: POC: make mxidoff 64 bits