On 25 October 2010 07:36, Tom Lane <t...@sss.pgh.pa.us> wrote:
> Brendan Jurd <dire...@gmail.com> writes:
>> I have encountered a reproducible segfault in Postgres ...
>
> Looks like the invalItems list has been clobbered:
>
> (gdb) p *root->glob->invalItems
> $6 = {type = 2139062143, length = 2139062143, head = 0x7f7f7f7f,
>  tail = 0x7f7f7f7f}
>
> I'm guessing it was modified in the temporary memory context and not
> properly copied out to the parent context when we finished inlining
> the function.
>

Hi Tom,

Thanks for the hint; I found that the attached patch resolved my
specific segfault, but I am wondering whether it goes far enough.  The
patch just copies invalItems up out of the temporary context before it
is deleted.  Could there also be changes to other elements of
PlannerGlobal that need to be saved?  Should we in fact be copying out
the whole of PlannerGlobal each time, and would that necessitate a new
copyfunc for it?

Cheers,
BJ
diff --git a/src/backend/optimizer/util/clauses.c 
b/src/backend/optimizer/util/clauses.c
index 13e89ec..b39ebb6 100644
--- a/src/backend/optimizer/util/clauses.c
+++ b/src/backend/optimizer/util/clauses.c
@@ -4300,12 +4300,13 @@ inline_set_returning_function(PlannerInfo *root, 
RangeTblEntry *rte)
                                                                                
                 fexpr->args);
 
        /*
-        * Copy the modified query out of the temporary memory context, and 
clean
-        * up.
+        * Copy the modified query, and the possibly-altered global invalidation
+        * list, out of the temporary memory context, and clean up.
         */
        MemoryContextSwitchTo(oldcxt);
 
        querytree = copyObject(querytree);
+       root->glob->invalItems = copyObject(root->glob->invalItems);
 
        MemoryContextDelete(mycxt);
        error_context_stack = sqlerrcontext.previous;
-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply via email to