Re: Fix memory leak in gist_page_items() of pageinspect

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Daniel Gustafsson <daniel(at)yesql(dot)se>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Michael Paquier <michael(at)paquier(dot)xyz>, Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fix memory leak in gist_page_items() of pageinspect
Date: 2025-12-13 02:37:40
Message-ID: CAEoWx2=0opy1W8+wX3hNBDYkYrWSETxd1t8OFvX7-u4zR17TVQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Dec 12, 2025, at 18:29, Daniel Gustafsson <daniel(at)yesql(dot)se> wrote:

On 12 Dec 2025, at 11:27, Heikki Linnakangas <hlinnaka(at)iki(dot)fi> wrote:

If we're going to bother changing this at all, let's consider reusing the
buffer. So instead of initStringInfo()+pfree on every tuple, allocate it
once and use resetStringInfo().

+1

It looks like there’s no disagreement on the index_close() fix, while the
StringInfo change has triggered some discussion.

So I’ve split the fix into two commits, which I probably should have done
from the beginning. 0001 contains the index_close() fix, and 0002 contains
the StringInfo fix.

As Heikki suggested, I switched to using resetStringInfo() in 0002. One
thing I’d like to highlight is that this function only uses the StringInfo
buffer under certain conditions. If we initialize the StringInfo
unconditionally, that feels wasteful; if we initialize it lazily, as in
0002, then we need some extra checks to manage its state.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachment Content-Type Size
v2-0002-pageinspect-clean-up-StringInfo-usage-in-gist_pag.patch application/octet-stream 1.8 KB
v2-0001-pageinspect-use-index_close-for-GiST-index-relati.patch application/octet-stream 1.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-12-13 02:44:11 Re: [PATCH] O_CLOEXEC not honored on Windows - handle inheritance chain
Previous Message Michael Paquier 2025-12-13 02:00:30 Re: [Proposal] Adding callback support for custom statistics kinds