Fix memory leak in gist_page_items() of pageinspect

Chao Li <li.evan.chao@gmail.com>

From: Chao Li <li.evan.chao@gmail.com>
To: Postgres hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-12-12T08:50:09Z
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 →
  1. Use relation_close() more consistently in contrib/

  2. Use table/index_close() more consistently

  3. pageinspect: use index_close() for GiST index relation

Attachments

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. This leak is inside a
per-tuple loop, thus it should be fixed.

In the meantime, the other small issue was also found in the same function.
An index is opened by index_open() but closed by index_close() and
relation_close() in different places. I also fixed the problem by changing
relation_close() to index_close().

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