summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2019-11-19 22:32:25 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2019-11-19 22:32:25 +0100
commite2768fbcdeba97d10c2beaea709412e6fb8b047d (patch)
tree77fb47c104cf134354861eef5827631c353668d6
parent8c5c361a0e312fd8dab699c322b2e4db3c598019 (diff)
downloadlibsigrokdecode-e2768fbcdeba97d10c2beaea709412e6fb8b047d.tar.gz
libsigrokdecode-e2768fbcdeba97d10c2beaea709412e6fb8b047d.zip
Fix multiple PyObject_SetAttrString() related leaks.
This fixes bug #1374.
-rw-r--r--instance.c7
-rw-r--r--type_decoder.c8
2 files changed, 10 insertions, 5 deletions
diff --git a/instance.c b/instance.c
index 52fb43b..85ff37e 100644
--- a/instance.c
+++ b/instance.c
@@ -140,6 +140,7 @@ SRD_API int srd_inst_option_set(struct srd_decoder_inst *di,
Py_DECREF(py_di_options);
py_di_options = PyDict_New();
PyObject_SetAttrString(di->py_inst, "options", py_di_options);
+ Py_DECREF(py_di_options);
for (l = di->decoder->options; l; l = l->next) {
sdo = l->data;
@@ -675,7 +676,7 @@ SRD_API int srd_inst_initial_pins_set_all(struct srd_decoder_inst *di, GArray *i
/** @private */
SRD_PRIV int srd_inst_start(struct srd_decoder_inst *di)
{
- PyObject *py_res;
+ PyObject *py_res, *py_samplenum;
GSList *l;
struct srd_decoder_inst *next_di;
int ret;
@@ -695,7 +696,9 @@ SRD_PRIV int srd_inst_start(struct srd_decoder_inst *di)
Py_DecRef(py_res);
/* Set self.samplenum to 0. */
- PyObject_SetAttrString(di->py_inst, "samplenum", PyLong_FromLong(0));
+ py_samplenum = PyLong_FromLong(0);
+ PyObject_SetAttrString(di->py_inst, "samplenum", py_samplenum);
+ Py_DECREF(py_samplenum);
/* Set self.matched to None. */
PyObject_SetAttrString(di->py_inst, "matched", Py_None);
diff --git a/type_decoder.c b/type_decoder.c
index b04747e..cde2900 100644
--- a/type_decoder.c
+++ b/type_decoder.c
@@ -850,7 +850,7 @@ static PyObject *Decoder_wait(PyObject *self, PyObject *args)
unsigned int i;
gboolean found_match;
struct srd_decoder_inst *di;
- PyObject *py_pinvalues, *py_matched;
+ PyObject *py_pinvalues, *py_matched, *py_samplenum;
PyGILState_STATE gstate;
if (!self || !args)
@@ -917,14 +917,16 @@ static PyObject *Decoder_wait(PyObject *self, PyObject *args)
/* If there's a match, set self.samplenum etc. and return. */
if (found_match) {
/* Set self.samplenum to the (absolute) sample number that matched. */
- PyObject_SetAttrString(di->py_inst, "samplenum",
- PyLong_FromLong(di->abs_cur_samplenum));
+ py_samplenum = PyLong_FromLong(di->abs_cur_samplenum);
+ PyObject_SetAttrString(di->py_inst, "samplenum", py_samplenum);
+ Py_DECREF(py_samplenum);
if (di->match_array && di->match_array->len > 0) {
py_matched = PyTuple_New(di->match_array->len);
for (i = 0; i < di->match_array->len; i++)
PyTuple_SetItem(py_matched, i, PyBool_FromLong(di->match_array->data[i]));
PyObject_SetAttrString(di->py_inst, "matched", py_matched);
+ Py_DECREF(py_matched);
match_array_free(di);
} else {
PyObject_SetAttrString(di->py_inst, "matched", Py_None);