]> granicus.if.org Git - postgresql/commitdiff
Prevent memory leaks in our various bison parsers when an error occurs
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 2 Sep 2008 20:37:55 +0000 (20:37 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 2 Sep 2008 20:37:55 +0000 (20:37 +0000)
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.

contrib/cube/cubeparse.y
contrib/seg/segparse.y
src/backend/bootstrap/bootparse.y
src/backend/parser/gram.y
src/pl/plpgsql/src/gram.y

index e867dc8731a8389779c1025a9ddcb867a85a3867..eefe5c47b991875e3778c57ad94b6bd564f0f4da 100644 (file)
@@ -2,7 +2,7 @@
 /* NdBox = [(lowerleft),(upperright)] */
 /* [(xLL(1)...xLL(N)),(xUR(1)...xUR(n))] */
 
-/* $PostgreSQL: pgsql/contrib/cube/cubeparse.y,v 1.17 2007/02/27 23:48:05 tgl Exp $ */
+/* $PostgreSQL: pgsql/contrib/cube/cubeparse.y,v 1.18 2008/09/02 20:37:54 tgl Exp $ */
 
 #define YYPARSE_PARAM result  /* need this to pass a pointer (void *) to yyparse */
 #define YYSTYPE char *
 
 #include "cubedata.h"
 
+/*
+ * 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
+
 extern int cube_yylex(void);
 
 static char *scanbuf;
index dc56fb580feecdd05b69d3405ae95bdde4a35e5b..47e3d398aaef24af015a06d2e41377aaa6977615 100644 (file)
@@ -9,6 +9,17 @@
 #include "utils/builtins.h"
 #include "segdata.h"
 
+/*
+ * 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
+
   extern int seg_yylex(void);
 
   extern int significant_digits(char *str);            /* defined in seg.c */
index 8019b244ae8cb2e1200a86445a4a1df95b81158b..9997566002e0f5f09a33d2bcc303d53449b29686 100644 (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 $
  *
  *-------------------------------------------------------------------------
  */
 #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)
 {
index 26a3198d37b960f1a94791c4e75cbb9016f3f059..5c716dd8f22cc6bd5237938eb66c1cf3bb6b5573 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.621 2008/09/01 20:42:44 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.622 2008/09/02 20:37:54 tgl Exp $
  *
  * HISTORY
  *       AUTHOR                        DATE                    MAJOR EVENT
  */
 #define base_yylex filtered_base_yylex
 
+/*
+ * 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
+
 extern List *parsetree;                        /* final parse result is delivered here */
 
 static bool QueryIsRule = FALSE;
index dfd37f67717a426d8374a32ce25a246e18b6e003..cf3c751cc0baeefa6cb015578b3b97c9279f6579 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.113 2008/05/15 22:39:49 tgl Exp $
+ *       $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.114 2008/09/02 20:37:55 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include "parser/parser.h"
 
 
+/*
+ * 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 PLpgSQL_expr            *read_sql_construct(int until,
                                                                                        int until2,
                                                                                        int until3,