On Fri, Mar 28, 2025 at 09:00:00PM +0200, Alexander Lakhin wrote:
> Please try the following query:
> BEGIN;
> SET LOCAL stats_fetch_consistency = snapshot;
> SELECT * FROM pg_stat_get_backend_wal(pg_backend_pid());
>
> with sanitizers (or under Valgrind). When I run it, I get:
> 2025-03-28 18:38:08.259 UTC [3415399] LOG: statement: SELECT * FROM pg_stat_get_backend_wal(pg_backend_pid());
> =================================================================
> ==3415399==ERROR: AddressSanitizer: heap-use-after-free on address
> 0x53100003c83c at pc 0x556e3d2d9967 bp 0x7ffda3cd2350 sp 0x7ffda3cd2340
> READ of size 4 at 0x53100003c83c thread T0
> #0 0x556e3d2d9966 in pgstat_fetch_stat_backend_by_pid .../src/backend/utils/activity/pgstat_backend.c:136
> #1 0x556e3d53b671 in pg_stat_get_backend_wal .../src/backend/utils/adt/pgstatfuncs.c:1673
> #2 0x556e3cb14045 in ExecMakeTableFunctionResult .../src/backend/executor/execSRF.c:234
> #3 0x556e3cb6c0fd in FunctionNext .../src/backend/executor/nodeFunctionscan.c:94
> #4 0x556e3cb171d2 in ExecScanFetch ../../../src/include/executor/execScan.h:126
> #5 0x556e3cb171d2 in ExecScanExtended ../../../src/include/executor/execScan.h:170
> #6 0x556e3cb171d2 in ExecScan .../src/backend/executor/execScan.c:59
> #7 0x556e3cb6bbf7 in ExecFunctionScan .../src/backend/executor/nodeFunctionscan.c:269
> #8 0x556e3cb0aba9 in ExecProcNodeFirst .../src/backend/executor/execProcnode.c:469
> ...
>
> Reproduced starting from 76def4cdd.
Thanks for the report. I have added an open item to not lose track of
this issue, and will get back to it when I can.
--
Michael