diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2018-05-08 20:44:05 +0200 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2018-05-09 01:32:37 +0200 |
commit | c1b2bbc11c5d44f9073d14485e750b9a75389d1f (patch) | |
tree | d5c4c6310e23021f27bc8f52892f5150b4cb1d34 | |
parent | b66bfd9573bada4d3249e9029e6c6c6112d7b4ac (diff) | |
download | libsigrokdecode-c1b2bbc11c5d44f9073d14485e750b9a75389d1f.tar.gz libsigrokdecode-c1b2bbc11c5d44f9073d14485e750b9a75389d1f.zip |
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.
-rw-r--r-- | type_decoder.c | 20 |
1 files changed, 20 insertions, 0 deletions
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: |