Re: Fix for segfault in plpython's exception handling

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Rafa de la Torre <rtorre(at)carto(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Fix for segfault in plpython's exception handling
Date: 2016-12-09 15:58:27
Message-ID: 17995.1481299107@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Rafa de la Torre <rtorre(at)carto(dot)com> writes:
> exc = PyErr_NewException(exception_map[i].name, base, dict);
> + Py_INCREF(exc);
> PyModule_AddObject(mod, exception_map[i].classname, exc);

Hm. Seems like if this is a problem, the code for the other three
exceptions is being a bit careless: it does do Py_INCREFs on them,
but not soon enough to ensure no problems. Also, I wonder why that
code checks for a null result from PyErr_NewException but this doesn't.

Good catch though. A naive person would have assumed that
PyModule_AddObject would increment the object's refcount, but
the Python docs say "This steals a reference to value", which
I guess must mean that the caller is required to do it.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2016-12-09 16:08:23 Re: Logical Replication WIP
Previous Message David G. Johnston 2016-12-09 15:56:38 Re: jsonb problematic operators