]> granicus.if.org Git - postgresql/commitdiff
Fix memory leak in PLySequence_ToJsonbValue()
authorAlexander Korotkov <akorotkov@postgresql.org>
Fri, 15 Jun 2018 12:01:46 +0000 (15:01 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Fri, 15 Jun 2018 12:01:46 +0000 (15:01 +0300)
PyObject returned from PySequence_GetItem() is not released.  Similar code in PLyMapping_ToJsonbValue() is correct, because according to Python documentation
PyList_GetItem() and PyTuple_GetItem() return a borrowed reference while
PySequence_GetItem() returns new reference.  contrib/jsonb_plpython is new
in PostgreSQL 11, no backpatch is needed.

Author: Nikita Glukhov
Discussion: https://postgr.es/m/6001af16-b242-2527-bc7e-84b8a959163b%40postgrespro.ru

contrib/jsonb_plpython/jsonb_plpython.c

index f752d6c3cd8e6c088418b71e0e5a9e96dbf99e57..d6d6eeb9c153cc5b5fb556ad21df39e5e2d38823 100644 (file)
@@ -308,6 +308,8 @@ PLySequence_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state)
                PyObject   *value = PySequence_GetItem(obj, i);
 
                (void) PLyObject_ToJsonbValue(value, jsonb_state, true);
+
+               Py_XDECREF(value);
        }
 
        return pushJsonbValue(jsonb_state, WJB_END_ARRAY, NULL);