Re: [PATCH] Make gram.y use palloc/pfree for memory management - Mailing list pgsql-hackers

From Marko Kreen
Subject Re: [PATCH] Make gram.y use palloc/pfree for memory management
Date
Msg-id e51f66da0809010633q5d0f999br72fe9dedf3b47760@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] Make gram.y use palloc/pfree for memory management  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [PATCH] Make gram.y use palloc/pfree for memory management  ("Marko Kreen" <markokr@gmail.com>)
List pgsql-hackers
First a correction, overriding malloc/free seems dangerous they
seems to leak out, so correct would be to use YYMALLOC/YYFREE.
This leaves 1.875 potentially leaking, but danger seems small.

On 9/1/08, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Marko Kreen <markokr@gmail.com> writes:
>  > This means gram.y can leak memory if error is throws in
>  > the middle of parsing.
>
> Please offer some evidence for that claim.

The leak occurs when
1. bison does allocation.
2. error is thrown.

Now, normally bison does not do allocation as it has initially 200-item
stack allocated in stack.  When this is full it does allocate.

But I'm not familial enough with bison internals and Postgres parser
structure, on how cause the stack fill up.  It may be that Postgres
parser avoids recursive stack allocations, thus in practice the
leak cannot occur.

-- 
marko


pgsql-hackers by date:

Previous
From: Hannu Krosing
Date:
Subject: Re: Is this really really as designed or defined in some standard
Next
From: "Marko Kreen"
Date:
Subject: Re: [PATCH] Cleanup of GUC units code