From 42f098074ba22951859672f1732269bd970c531c Mon Sep 17 00:00:00 2001 From: Kelvin Rodriguez Date: Thu, 13 Dec 2018 16:52:14 -0700 Subject: [PATCH] moved derefs to be called as soon as var is no longer needed --- src/ale.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ale.cpp b/src/ale.cpp index 576e57b..8c930e3 100644 --- a/src/ale.cpp +++ b/src/ale.cpp @@ -296,7 +296,7 @@ namespace ale { return std::string(error_description) + "\n" + std::string(full_backtrace); } - + // no traceback to return return ""; } @@ -340,6 +340,9 @@ namespace ale { // Call the function with the arguments. PyObject* pResult = PyObject_CallObject(pFunc, pArgs); + Py_DECREF(pArgs); + Py_DECREF(pFunc); + Py_DECREF(pString); if(!pResult) { throw invalid_argument(getPyTraceback()); } @@ -355,13 +358,8 @@ namespace ale { char *temp_str = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer cResult = temp_str; // copy into std::string - Py_DECREF(temp_str); Py_DECREF(pResultStr); - Py_DECREF(temp_bytes); - Py_DECREF(pArgs); - Py_DECREF(pModule); - Py_DECREF(pString); return cResult; } -- GitLab