From 9eb13b0ca8c60905ac44d0a3e2212947feb9e679 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 5 May 2017 22:54:51 -0700 Subject: [PATCH] Fix memory leaks remaining in code. --- src/pyliblexmodule.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pyliblexmodule.c b/src/pyliblexmodule.c index 43f51b3..90540b7 100644 --- a/src/pyliblexmodule.c +++ b/src/pyliblexmodule.c @@ -6,6 +6,7 @@ static void _pyliblex_free_eval(PyObject* object){ eval_config* config = PyCapsule_GetPointer(object, NULL); if(config){ liblex_result result = eval_config_free(config); + free(config); if(result != LIBLEX_SUCCESS){ PyErr_NoMemory(); } @@ -69,9 +70,10 @@ static int _pyliblex_add_match(void* data, va_list args){ } if(tuple) { - if(return_code != 0) Py_DECREF(tuple); - else return_code = PyList_Append(list, tuple); + if(return_code == 0) return_code = PyList_Append(list, tuple); + Py_DECREF(tuple); } + return return_code; } static PyObject* pyliblex_lex(PyObject* self, PyObject* args){