Re: pl/python tracebacks - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: pl/python tracebacks
Date
Msg-id 1298551735.4783.4.camel@vanquo.pezone.net
Whole thread Raw
In response to Re: pl/python tracebacks  (Jan Urbański <wulczer@wulczer.org>)
List pgsql-hackers
On lör, 2011-02-12 at 10:07 +0100, Jan Urbański wrote:
> > PLyUnicode_AsString(PyObject *unicode)
> > {
> >     PyObject   *o = PLyUnicode_Bytes(unicode);
> >     char       *rv = pstrdup(PyBytes_AsString(o));
> > 
> >     Py_XDECREF(o);
> >     return rv;
> > }
> > 
> > PyString_AsString is used all over the place without any pfrees. But
> I
> > have no Idea how that pstrdup() is getting freed if at all.
> > 
> > Care to enlighten me ?
> 
> Ooops, seems that this hack that's meant to improve compatibility with
> Python3 makes it leak. I wonder is the pstrdup is necessary here,

The result of PyBytes_AsString(o) points into the internal storage of o,
which is released (effectively freed) by the decref on the next line.
So you'd better make a copy if you want to keep using it.



pgsql-hackers by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: Invitation to Cluster Hackers meeting at pgCon
Next
From: Fujii Masao
Date:
Subject: Re: Sync Rep v17