Andres Freund <and...@anarazel.de> writes:
> The one I measured was 9.0 only:

>  diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c
>  index 6063628..a6dd9d0 100644
>  *** a/src/pl/plpython/plpython.c
>  --- b/src/pl/plpython/plpython.c
>  *************** plpython_inline_handler(PG_FUNCTION_ARGS
>  *** 538,546 ****
>  --- 538,548 ----
>                  PLy_procedure_compile(proc, codeblock->source_text);
>                  PLy_curr_procedure = proc;
>                  PLy_function_handler(&fake_fcinfo, proc);
>  +               PLy_free(proc);
>          }
>          PG_CATCH();
>          {
>  +               PLy_free(proc);
>                  PLy_curr_procedure = save_curr_proc;
>                  PyErr_Clear();
>                  PG_RE_THROW();


> Found by running something like:

> while true; do echo 'DO LANGUAGE plpythonu $$import 
> gc;gc.collect();plpy.execute("SELECT unknown"); $$;';done|psql -h /tmp -p 
> 5433 
> postgres

I tried this and found there was still a leak after applying your patch.
What seems like the correct thing is to use PLy_procedure_delete(),
as in the attached applied patch.  With this, I see zero leak rate for
either this test or the no-error-thrown variant.

This shows that there is a pre-existing leak in PLy_procedure_delete(),
since it was failing to release the proc block itself.  I did not bother
to back-patch that, though, because the one pre-existing call was not in
a place where it'd be likely to get executed over and over.

Thanks for the report!

                        regards, tom lane


Index: plpython.c
===================================================================
RCS file: /cvsroot/pgsql/src/pl/plpython/plpython.c,v
retrieving revision 1.142
diff -c -r1.142 plpython.c
*** plpython.c  30 Apr 2010 19:15:45 -0000      1.142
--- plpython.c  1 May 2010 17:03:35 -0000
***************
*** 541,552 ****
--- 541,555 ----
        }
        PG_CATCH();
        {
+               PLy_procedure_delete(proc);
                PLy_curr_procedure = save_curr_proc;
                PyErr_Clear();
                PG_RE_THROW();
        }
        PG_END_TRY();
  
+       PLy_procedure_delete(proc);
+ 
        /* Pop the error context stack */
        error_context_stack = plerrcontext.previous;
  
***************
*** 1664,1669 ****
--- 1667,1673 ----
        }
        if (proc->argnames)
                PLy_free(proc->argnames);
+       PLy_free(proc);
  }
  
  /*

-- 
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