From 7f1d5fa9c351bc7129cf7a6e65b23e8778a00910 Mon Sep 17 00:00:00 2001 From: KerstinKeller Date: Tue, 1 Oct 2024 17:02:38 +0200 Subject: [PATCH] [Python] Fix memory leaks in Python wrapper by adding missing Py_DECREF. (#1754) --- lang/python/core/src/ecal_wrap.cxx | 6 ++++-- lang/python/ecalhdf5/src/ecalhdf5_wrap.cxx | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lang/python/core/src/ecal_wrap.cxx b/lang/python/core/src/ecal_wrap.cxx index 641345f751..54560981a7 100644 --- a/lang/python/core/src/ecal_wrap.cxx +++ b/lang/python/core/src/ecal_wrap.cxx @@ -1489,7 +1489,8 @@ PyObject* mon_monitoring(PyObject* /*self*/, PyObject* /*args*/) } } - return(Py_BuildValue("iO", 0, retDict)); + auto* retVal = Py_BuildValue("iO", 0, retDict); Py_DECREF(retDict); + return(retVal); } /****************************************/ @@ -1533,7 +1534,8 @@ PyObject* mon_logging(PyObject* /*self*/, PyObject* /*args*/) } } - return(Py_BuildValue("iO", 0, retList)); + auto* retVal = Py_BuildValue("iO", 0, retList); Py_DECREF(retList); + return(retVal); } /****************************************/ diff --git a/lang/python/ecalhdf5/src/ecalhdf5_wrap.cxx b/lang/python/ecalhdf5/src/ecalhdf5_wrap.cxx index 6431163be6..ec5744c3f0 100644 --- a/lang/python/ecalhdf5/src/ecalhdf5_wrap.cxx +++ b/lang/python/ecalhdf5/src/ecalhdf5_wrap.cxx @@ -1,6 +1,6 @@ /* ========================= eCAL LICENSE ================================= * - * Copyright (C) 2016 - 2019 Continental Corporation + * Copyright (C) 2016 - 2024 Continental Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -178,7 +178,7 @@ static PyObject* Meas_GetChannelNames(Meas *self, PyObject* /*args*/) for (const auto& channel : channel_names) { PyObject* ch = Py_BuildValue("s", channel.c_str()); - PyList_Append(channels, ch); + PyList_Append(channels, ch); Py_DECREF(ch); } return channels;