summaryrefslogtreecommitdiff
path: root/instance.c
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2019-11-23 16:16:35 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2019-11-23 17:08:15 +0100
commit144a09700d242ceac48a739f9fcdb3649f4c72b8 (patch)
tree092a8dc2ec9b1087a7cd82ca30609f8714cd3f7a /instance.c
parentb62ca656bcead79c54b14b0c83b0fd89ad76fb0c (diff)
downloadlibsigrokdecode-144a09700d242ceac48a739f9fcdb3649f4c72b8.tar.gz
libsigrokdecode-144a09700d242ceac48a739f9fcdb3649f4c72b8.zip
srd_inst_option_set(): Fix multiple memory leaks.
These were reported when compiling with "-fsanitize=address" and running "PYTHONMALLOC=malloc make check": ================================================================= ==42879==ERROR: LeakSanitizer: detected memory leaks Direct leak of 317 byte(s) in 6 object(s) allocated from: #0 0x7f08e4809538 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144 #1 0x7f08e3f37622 in PyUnicode_New ../Objects/unicodeobject.c:1365 Direct leak of 28 byte(s) in 1 object(s) allocated from: #0 0x7f08e4809538 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144 #1 0x7f08e3f7e1a5 in _PyLong_New ../Objects/longobject.c:275 Direct leak of 24 byte(s) in 1 object(s) allocated from: #0 0x7f08e4809538 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144 #1 0x7f08e3f91521 in PyFloat_FromDouble ../Objects/floatobject.c:122 SUMMARY: AddressSanitizer: 369 byte(s) leaked in 8 allocation(s). session
Diffstat (limited to 'instance.c')
-rw-r--r--instance.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/instance.c b/instance.c
index 85ff37e..fc03174 100644
--- a/instance.c
+++ b/instance.c
@@ -182,10 +182,13 @@ SRD_API int srd_inst_option_set(struct srd_decoder_inst *di,
goto err_out;
}
}
- if (PyDict_SetItemString(py_di_options, sdo->id, py_optval) == -1)
+ if (PyDict_SetItemString(py_di_options, sdo->id, py_optval) == -1) {
+ Py_XDECREF(py_optval);
goto err_out;
+ }
/* Not harmful even if we used the default. */
g_hash_table_remove(options, sdo->id);
+ Py_XDECREF(py_optval);
}
if (g_hash_table_size(options) != 0)
srd_warn("Unknown options specified for '%s'", di->inst_id);
@@ -193,7 +196,6 @@ SRD_API int srd_inst_option_set(struct srd_decoder_inst *di,
ret = SRD_OK;
err_out:
- Py_XDECREF(py_optval);
if (PyErr_Occurred()) {
srd_exception_catch("Stray exception in srd_inst_option_set()");
ret = SRD_ERR_PYTHON;