Re: [PATCH] Free memory allocated by waitonlock_error_callback()

From: Quan Zongliang <quanzongliang(at)yeah(dot)net>
To: Aleksander Alekseev <aleksander(at)tigerdata(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: [PATCH] Free memory allocated by waitonlock_error_callback()
Date: 2025-10-23 03:18:09
Message-ID: 81814f78-e67d-4af9-8fbc-ea044f7355d5@yeah.net
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 9/19/25 7:16 PM, Aleksander Alekseev wrote:
> Hi,
>
> Currently waitonlock_error_callback() allocates memory in ErrorContext
> and doesn't explicitly free it. Valgrind is not happy about it and
> generates multiple reports like this:
>
> ```
> 2,048 bytes in 2 blocks are definitely lost in loss record 1,097 of 1,165
> at 0x999539: palloc (mcxt.c:1389)
> by 0x9DCBFD: initStringInfoInternal (stringinfo.c:45)
> by 0x9DCC9D: initStringInfo (stringinfo.c:99)
> by 0x73A807: waitonlock_error_callback (lock.c:2027)
> by 0x94E1DE: errfinish (elog.c:510)
> by 0x750394: ProcSleep (proc.c:1614)
> by 0x73A720: WaitOnLock (lock.c:1979)
> by 0x7391C2: LockAcquireExtended (lock.c:1221)
> by 0x738360: LockAcquire (lock.c:814)
> by 0x741064: VirtualXactLock (lock.c:4844)
> by 0x3E9D93: WaitForOlderSnapshots (indexcmds.c:492)
> by 0x3F155B: ReindexRelationConcurrently (indexcmds.c:4216)
> ```
>
> I propose adding pfree().
>
> waitonlock_error_callback() was added in:
>
> ```
> commit f727b63e810724c7187f38b2580b2915bdbc3c9c
> Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
> Date: Fri Aug 29 15:43:34 2025 -0400
>
> Provide error context when an error is thrown within WaitOnLock().
> ```
>

LGTM

Improve the completeness of the code.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2025-10-23 03:28:05 Re: POC: enable logical decoding when wal_level = 'replica' without a server restart
Previous Message David Rowley 2025-10-23 03:07:00 Re: Issue with query_is_distinct_for() and grouping sets