type_decoder: Fixup memory leak in Decoder.put() (meta, python)
authorUwe Hermann <uwe@hermann-uwe.de>
Tue, 8 May 2018 23:31:10 +0000 (01:31 +0200)
committerUwe Hermann <uwe@hermann-uwe.de>
Tue, 8 May 2018 23:33:10 +0000 (01:33 +0200)
This fixes parts of bug #329.

type_decoder.c

index 79e9c4924ebd3083605037a0b42b051a53bcf024..aa92c3b22490d9e68813661bbd80c7e7575e89e2 100644 (file)
@@ -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;