Re: pl/python tracebacks

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Jan Urbański <wulczer(at)wulczer(dot)org>
Cc: Alex Hunsaker <badalex(at)gmail(dot)com>, Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pl/python tracebacks
Date: 2011-02-24 12:48:55
Message-ID: 1298551735.4783.4.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2011-02-24 12:50:36 Re: Invitation to Cluster Hackers meeting at pgCon
Previous Message Peter Eisentraut 2011-02-24 12:46:00 Re: pl/python tracebacks