From a61c930aaaa50ae79207f53a9d8e7a76397bcec7 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 12 Apr 2021 00:06:00 +0200 Subject: [PATCH] Py: fix memory leak --- src/Base/QuantityPyImp.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Base/QuantityPyImp.cpp b/src/Base/QuantityPyImp.cpp index 60266fd737..90af3385bd 100644 --- a/src/Base/QuantityPyImp.cpp +++ b/src/Base/QuantityPyImp.cpp @@ -672,25 +672,31 @@ void QuantityPy::setFormat(Py::Dict arg) PyObject *QuantityPy::getCustomAttributes(const char* attr) const { + QuantityPy* py = nullptr; if (strcmp(attr, "Torr") == 0) { - return new QuantityPy(new Quantity(Quantity::Torr)); + py = new QuantityPy(new Quantity(Quantity::Torr)); } else if (strcmp(attr, "mTorr") == 0) { - return new QuantityPy(new Quantity(Quantity::mTorr)); + py = new QuantityPy(new Quantity(Quantity::mTorr)); } else if (strcmp(attr, "yTorr") == 0) { - return new QuantityPy(new Quantity(Quantity::yTorr)); + py = new QuantityPy(new Quantity(Quantity::yTorr)); } else if (strcmp(attr, "PoundForce") == 0) { - return new QuantityPy(new Quantity(Quantity::PoundForce)); + py = new QuantityPy(new Quantity(Quantity::PoundForce)); } else if (strcmp(attr, "AngularMinute") == 0) { - return new QuantityPy(new Quantity(Quantity::AngMinute)); + py = new QuantityPy(new Quantity(Quantity::AngMinute)); } else if (strcmp(attr, "AngularSecond") == 0) { - return new QuantityPy(new Quantity(Quantity::AngSecond)); + py = new QuantityPy(new Quantity(Quantity::AngSecond)); } - return 0; + + if (py) { + py->setNotTracking(); + } + + return py; } int QuantityPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)