From f2d62eb5a19535a1955bc21cb6363e36272b11ef Mon Sep 17 00:00:00 2001 From: Will Newton Date: Tue, 4 Oct 2016 16:06:05 +0100 Subject: [PATCH] iwlib/utils.h: Avoid leaking reference to object If we don't decrement the reference count of the object we insert into the dictionary then we will leak the object later. http://nedbatchelder.com/blog/200911/memory_leak_mystery.html --- iwlib/utils.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iwlib/utils.h b/iwlib/utils.h index fc37ea2..0589c82 100644 --- a/iwlib/utils.h +++ b/iwlib/utils.h @@ -13,8 +13,10 @@ #define SAFE_SETITEMSTRING(dict, key, value) do { \ PyObject *__tmp; \ __tmp = value; \ - if (__tmp) \ + if (__tmp) { \ PyDict_SetItemString(dict, key, __tmp); \ + Py_DECREF(__tmp); \ + } \ } while(0)