pgsql: Fix memory leak in pgstat_progress_parallel_incr_param()

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix memory leak in pgstat_progress_parallel_incr_param()
Date: 2026-06-08 06:29:51
Message-ID: E1wWTUd-001Yb3-2n@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix memory leak in pgstat_progress_parallel_incr_param()

When called from a parallel worker, this function calls initStringInfo()
and pq_beginmessage(), causing a StringInfo allocation to happen twice.
pq_endmessage() frees only the second allocation, with each call leaking
~1 kB into the per-worker memory context. This could cause a few
hundred megabytes worth of memory to pile up until the worker exits (the
message allocations happen in the parallel worker context), with the
situation being worse the longer a parallel worker runs.

Oversight in f1889729dd3.

Author: Baji Shaik <baji(dot)pgdev(at)gmail(dot)com>
Reviewed-by: Sami Imseih <samimseih(at)gmail(dot)com>
Reviewed-by: Tristan Partin <tristan(at)partin(dot)io>
Discussion: https://postgr.es/m/CA+fm-RMopta1Dmq8udiU5sp+zwTvhUf4+xfbr3rZDfczH+p-xw@mail.gmail.com
Backpatch-through: 17

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b20c952ce70370b22ea7a206d7b674a322397d28

Modified Files
--------------
src/backend/utils/activity/backend_progress.c | 2 --
1 file changed, 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Kapila 2026-06-08 06:56:37 pgsql: pg_createsubscriber: Fix duplicate publication name rejection.
Previous Message Peter Eisentraut 2026-06-08 06:23:59 pgsql: Fix incorrect format placeholders