pgsql: Fix memory leak in pgoutput with relation attribute map

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix memory leak in pgoutput with relation attribute map
Date: 2025-01-07 23:47:51
Message-ID: E1tVJIc-000Pg1-SD@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix memory leak in pgoutput with relation attribute map

pgoutput caches the attribute map of a relation, that is free()'d only
when validating a RelationSyncEntry. However, this code path is not
taken when calling any of the SQL functions able to do some logical
decoding, like pg_logical_slot_{get,peek}_changes(), leaking some memory
into CacheMemoryContext on repeated calls.

This is a follow-up of c9b3d4909bbf, this time for v13 and v14. The
relation attribute map is stored in a dedicated memory context, tracked
with a static variable whose state is reset with a MemoryContext reset
callback attached to PGOutputData->context. This implementation is
similar to the approach taken by cfd6cbcf9be0.

Reported-by: Masahiko Sawada
Author: Vignesh C
Reviewed-by: Hou Zhijie
Discussion: https://postgr.es/m/CAD21AoDkAhQVSukOfH3_reuF-j4EU0-HxMqU3dU+bSTxsqT14Q@mail.gmail.com
Discussion: https://postgr.es/m/CALDaNm1hewNAsZ_e6FF52a=9drmkRJxtEPrzCB6-9mkJyeBBqA@mail.gmail.com
Backpatch-through: 13

Branch
------
REL_13_STABLE

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

Modified Files
--------------
src/backend/replication/pgoutput/pgoutput.c | 30 +++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Thomas Munro 2025-01-08 04:12:48 pgsql: Fix C error reported by Oracle compiler.
Previous Message Jeff Davis 2025-01-07 23:15:37 pgsql: ExecInitAgg: update aggstate->numaggs and ->numtrans earlier.