From: Uwe Hermann Date: Tue, 8 May 2018 23:31:10 +0000 (+0200) Subject: type_decoder: Fixup memory leak in Decoder.put() (meta, python) X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=287e2788a726732e5f29eb3f5f4fe9d68fac4d05;p=libsigrokdecode.git type_decoder: Fixup memory leak in Decoder.put() (meta, python) This fixes parts of bug #329. --- diff --git a/type_decoder.c b/type_decoder.c index 79e9c49..aa92c3b 100644 --- a/type_decoder.c +++ b/type_decoder.c @@ -247,6 +247,13 @@ err: return SRD_ERR_PYTHON; } +static void release_meta(GVariant *gvar) +{ + if (!gvar) + return; + g_variant_unref(gvar); +} + static PyObject *Decoder_put(PyObject *self, PyObject *args) { GSList *l; @@ -259,6 +266,8 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args) struct srd_pd_callback *cb; PyGILState_STATE gstate; + py_data = NULL; + gstate = PyGILState_Ensure(); if (!(di = srd_inst_find_by_obj(NULL, self))) { @@ -351,6 +360,7 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args) Py_BEGIN_ALLOW_THREADS cb->cb(&pdata, cb->cb_data); Py_END_ALLOW_THREADS + release_meta(pdata.data); } break; default: @@ -359,11 +369,17 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args) break; } + if (py_data) + Py_DECREF(py_data); + PyGILState_Release(gstate); Py_RETURN_NONE; err: + if (py_data) + Py_DECREF(py_data); + PyGILState_Release(gstate); return NULL;