Working on the new lazy transform for jsonb I found another memory leak in PLyObject_ToJsonbValue(): palloc() for output boolean JsonbValue is unnecessary, 'out' variable is already initialized.
Fix is attached. On 15.06.2018 14:42, Alexander Korotkov wrote:
Hi! On Fri, Jun 15, 2018 at 2:11 PM Nikita Glukhov <n.glu...@postgrespro.ru> wrote: I found a memory leak in PLySequence_ToJsonbValue(): PyObject returned from PySequence_GetItem() is not released. A bug can be easily reproduced using function roudtrip() from regression test: SELECT roundtrip('[1,2,3]'::jsonb) FROM generate_series(1, 1000000); Similar code in PLyMapping_ToJsonbValue() seems to be correct because PyList_GetItem() and PyTuple_GetItem() return a borrowed reference. Patch with fix is attached. I'm going to check and commit this if everything is OK. ------ Alexander Korotkov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company
-- Nikita Glukhov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company
>From 06e22b5ff12486917259270c8f2a95b1a5d7cee2 Mon Sep 17 00:00:00 2001 From: Nikita Glukhov <n.glu...@postgrespro.ru> Date: Tue, 7 Aug 2018 13:37:10 +0300 Subject: [PATCH] Fix memory leak in PLyObject_ToJsonbValue() --- contrib/jsonb_plpython/jsonb_plpython.c | 1 - 1 file changed, 1 deletion(-) diff --git a/contrib/jsonb_plpython/jsonb_plpython.c b/contrib/jsonb_plpython/jsonb_plpython.c index d6d6eeb..f44d364 100644 --- a/contrib/jsonb_plpython/jsonb_plpython.c +++ b/contrib/jsonb_plpython/jsonb_plpython.c @@ -398,7 +398,6 @@ PLyObject_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state, bool is_ele */ else if (PyBool_Check(obj)) { - out = palloc(sizeof(JsonbValue)); out->type = jbvBool; out->val.boolean = (obj == Py_True); } -- 2.7.4