1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-21 16:02:15 +03:00

Prevent memory leaks in our various bison parsers when an error occurs

during parsing.  Formerly the parser's stack was allocated with malloc
and so wouldn't be reclaimed; this patch makes it use palloc instead,
so that flushing the current context will reclaim the memory.  Per
Marko Kreen.
This commit is contained in:
Tom Lane
2008-09-02 20:37:55 +00:00
parent dd6edd5efd
commit fbb2b69c8f
5 changed files with 60 additions and 4 deletions

View File

@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.93 2008/09/01 20:42:43 tgl Exp $
* $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.94 2008/09/02 20:37:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -54,6 +54,17 @@
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
/*
* Bison doesn't allocate anything that needs to live across parser calls,
* so we can easily have it use palloc instead of malloc. This prevents
* memory leaks if we error out during parsing. Note this only works with
* bison >= 2.0. However, in bison 1.875 the default is to use alloca()
* if possible, so there's not really much problem anyhow, at least if
* you're building with gcc.
*/
#define YYMALLOC palloc
#define YYFREE pfree
static void
do_start(void)
{