[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-general
Subject:    [HACKERS] [PATCH] Make gram.y use palloc/pfree for memory management
From:       Marko Kreen <markokr () gmail ! com>
Date:       2008-08-31 22:17:27
Message-ID: 20080831221727.18573.11996.stgit () lapp
[Download RAW message or body]

This is a MIME message.


Currently gram.y uses malloc/free for memory management,
but all pointers are local to function.  Unlike flex-based
scan.l which has static references to buffers and reuses them
across calls.

This means gram.y can leak memory if error is throws in
the middle of parsing.

The patch redefines malloc/free to palloc/pfree to fix the leak.

I did not use YYSTACK_ALLOC / YYSTACK_FREE that exists in newer bison,
because bison 1.875 does not support those.
["gram-memleak-fix.patch" (gram-memleak-fix.patch)]

*** a/src/backend/parser/gram.y
--- b/src/backend/parser/gram.y
***************
*** 60,69 ****
--- 60,75 ----
  #include "utils/date.h"
  #include "utils/datetime.h"
  #include "utils/numeric.h"
  #include "utils/xml.h"
  
+ /*
+  * bison does not re-use buffers, so we can redefine malloc/free
+  * to palloc/pfree.
+  */
+ #define malloc palloc
+ #define free   pfree
  
  /* Location tracking support --- simpler than bison's default */
  #define YYLLOC_DEFAULT(Current, Rhs, N) \
  	do { \
  		if (N) \
*************** TableFuncTypeName(List *columns)
*** 10017,10022 ****
--- 10023,10032 ----
   * Must undefine base_yylex before including scan.c, since we want it
   * to create the function base_yylex not filtered_base_yylex.
   */
  #undef base_yylex
  
+ /* scan.c needs real malloc */
+ #undef malloc
+ #undef free
+ 
  #include "scan.c"


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic