diff Sources/Plugin.cpp @ 127:a862d554753f fix-leak

fixing leaks associated with setting integers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Aug 2023 10:47:30 +0200
parents 35c0b2fc751c
children c55b0583084b
line wrap: on
line diff
--- a/Sources/Plugin.cpp	Wed Aug 30 10:32:26 2023 +0200
+++ b/Sources/Plugin.cpp	Wed Aug 30 10:47:30 2023 +0200
@@ -81,11 +81,31 @@
       PythonLock lock;
       
       PythonObject kw(lock, PyDict_New());
-      PyDict_SetItemString(kw.GetPyObject(), "Group", PyLong_FromUnsignedLong(entry.group));
-      PyDict_SetItemString(kw.GetPyObject(), "Element", PyLong_FromUnsignedLong(entry.element));
-      PyDict_SetItemString(kw.GetPyObject(), "ValueRepresentation", PyLong_FromUnsignedLong(entry.vr));
-      PyDict_SetItemString(kw.GetPyObject(), "MinMultiplicity", PyLong_FromUnsignedLong(entry.minMultiplicity));
-      PyDict_SetItemString(kw.GetPyObject(), "MaxMultiplicity", PyLong_FromUnsignedLong(entry.maxMultiplicity));
+
+      {
+        PythonObject tmp(lock, PyLong_FromUnsignedLong(entry.group));
+        PyDict_SetItemString(kw.GetPyObject(), "Group", tmp.GetPyObject());
+      }
+
+      {
+        PythonObject tmp(lock, PyLong_FromUnsignedLong(entry.element));
+        PyDict_SetItemString(kw.GetPyObject(), "Element", tmp.GetPyObject());
+      }
+
+      {
+        PythonObject tmp(lock, PyLong_FromUnsignedLong(entry.vr));
+        PyDict_SetItemString(kw.GetPyObject(), "ValueRepresentation", tmp.GetPyObject());
+      }
+
+      {
+        PythonObject tmp(lock, PyLong_FromUnsignedLong(entry.minMultiplicity));
+        PyDict_SetItemString(kw.GetPyObject(), "MinMultiplicity", tmp.GetPyObject());
+      }
+
+      {
+        PythonObject tmp(lock, PyLong_FromUnsignedLong(entry.maxMultiplicity));
+        PyDict_SetItemString(kw.GetPyObject(), "MaxMultiplicity", tmp.GetPyObject());
+      }
       
       return kw.Release();
     }