Re: Memory leak in pg_stat_statements when qtext file contains invalid encoding
Gaurav Singh <gaurav.singh@yugabyte.com>
From: Gaurav Singh <gaurav.singh@yugabyte.com>
To: daniel@yesql.se
Cc: Lukas Fittl <lukas@fittl.com>, pgsql-bugs@lists.postgresql.org
Date: 2026-03-27T08:57:37Z
Lists: pgsql-bugs
> We could also use palloc_extended() with MCXT_ALLOC_NO_OOM to avoid erroring > out on OOM and be able to return NULL? Oh, it seems palloc_extended() would be a better fix. -- Gaurav On Fri, Mar 27, 2026 at 2:21 PM Daniel Gustafsson <daniel@yesql.se> wrote: > > On 27 Mar 2026, at 09:21, Lukas Fittl <lukas@fittl.com> wrote: > > > But I think you're correct about qbuffer - because that buffer is > > using malloc (not palloc), its not part of any memory context, and so > > it will happily leak on abort. > > > > It appears our use of malloc in pg_stat_statements is so that we can > > fail on OOM and return NULL without a jump. I think that makes sense > > for when a GC cycle was triggered during regular query execution > > (since we don't want to error the original query), but it seems like > > just bubbling up the OOM if needed when querying the > > pg_stat_statements function seems fine. > > We could also use palloc_extended() with MCXT_ALLOC_NO_OOM to avoid > erroring > out on OOM and be able to return NULL? > > -- > Daniel Gustafsson > >
Commits
-
Avoid memory leak on error while parsing pg_stat_statements dump file
- 3c74cb5762db 19 (unreleased) landed
- a6d03067ff5d 14.23 landed
- 92cf11171baf 15.18 landed
- 52edaf9d9b02 16.14 landed
- 351e59f344b5 17.10 landed
- 25b02320e133 18.4 landed