mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Avoid Python memory leaks in hstore_plpython and jsonb_plpython.
Fix some places where we might fail to do Py_DECREF() on a Python object (thereby leaking it for the rest of the session). Almost all of the risks were in error-recovery paths, which we don't really expect to hit anyway. Hence, while this is definitely a bug fix, it doesn't quite seem worth back-patching. Nikita Glukhov, Michael Paquier, Tom Lane Discussion: https://postgr.es/m/28053a7d-10d8-fc23-b05c-b4749c873f63@postgrespro.ru
This commit is contained in:
@ -128,9 +128,9 @@ Datum
|
||||
plpython_to_hstore(PG_FUNCTION_ARGS)
|
||||
{
|
||||
PyObject *dict;
|
||||
PyObject *volatile items = NULL;
|
||||
int32 pcount;
|
||||
HStore *out;
|
||||
PyObject *volatile items;
|
||||
Py_ssize_t pcount;
|
||||
HStore *volatile out;
|
||||
|
||||
dict = (PyObject *) PG_GETARG_POINTER(0);
|
||||
if (!PyMapping_Check(dict))
|
||||
@ -144,7 +144,7 @@ plpython_to_hstore(PG_FUNCTION_ARGS)
|
||||
PG_TRY();
|
||||
{
|
||||
int32 buflen;
|
||||
int32 i;
|
||||
Py_ssize_t i;
|
||||
Pairs *pairs;
|
||||
|
||||
pairs = palloc(pcount * sizeof(*pairs));
|
||||
@ -176,7 +176,6 @@ plpython_to_hstore(PG_FUNCTION_ARGS)
|
||||
pairs[i].isnull = false;
|
||||
}
|
||||
}
|
||||
Py_DECREF(items);
|
||||
|
||||
pcount = hstoreUniquePairs(pairs, pcount, &buflen);
|
||||
out = hstorePairs(pairs, pcount, buflen);
|
||||
@ -188,5 +187,7 @@ plpython_to_hstore(PG_FUNCTION_ARGS)
|
||||
}
|
||||
PG_END_TRY();
|
||||
|
||||
Py_DECREF(items);
|
||||
|
||||
PG_RETURN_POINTER(out);
|
||||
}
|
||||
|
Reference in New Issue
Block a user