From: Gerhard Sittig Date: Tue, 8 May 2018 18:44:05 +0000 (+0200) Subject: type_decoder: fixup memory leak in Decoder.put() (annotation, binary) X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c1b2bbc11c5d44f9073d14485e750b9a75389d1f;p=libsigrokdecode.git type_decoder: fixup memory leak in Decoder.put() (annotation, binary) The text presentation of decoder annotations' payload data was allocated but not freed. As were the byte strings of binary output. Fix it. This fixes parts of bug #329. --- diff --git a/type_decoder.c b/type_decoder.c index 880dbad..79e9c49 100644 --- a/type_decoder.c +++ b/type_decoder.c @@ -40,6 +40,15 @@ static const char *output_type_name(unsigned int idx) return names[MIN(idx, G_N_ELEMENTS(names) - 1)]; } +static void release_annotation(struct srd_proto_data_annotation *pda) +{ + if (!pda) + return; + if (pda->ann_text) + g_strfreev(pda->ann_text); + g_free(pda); +} + static int convert_annotation(struct srd_decoder_inst *di, PyObject *obj, struct srd_proto_data *pdata) { @@ -112,6 +121,15 @@ err: return SRD_ERR_PYTHON; } +static void release_binary(struct srd_proto_data_binary *pdb) +{ + if (!pdb) + return; + if (pdb->data) + g_free((void *)pdb->data); + g_free(pdb); +} + static int convert_binary(struct srd_decoder_inst *di, PyObject *obj, struct srd_proto_data *pdata) { @@ -287,6 +305,7 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args) Py_BEGIN_ALLOW_THREADS cb->cb(&pdata, cb->cb_data); Py_END_ALLOW_THREADS + release_annotation(pdata.data); } break; case SRD_OUTPUT_PYTHON: @@ -319,6 +338,7 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args) Py_BEGIN_ALLOW_THREADS cb->cb(&pdata, cb->cb_data); Py_END_ALLOW_THREADS + release_binary(pdata.data); } break; case SRD_OUTPUT_META: