Salome HOME
Deal with 2D/0D pointlocator into Remapper
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingRemapperCommon.i
index 4c0c0188bf3a7e6305acbdafcf823f9c6dbe74e8..e77d21d843b75d578e4624106caa1e50f8807c46 100644 (file)
@@ -26,6 +26,7 @@
 
 %{
 #include "MEDCouplingRemapper.hxx"
+#include <memory>
 %}
 
 %include "InterpolationOptions.hxx"
@@ -77,7 +78,10 @@ namespace MEDCoupling
                  const std::map<mcIdType,double>& row=m[i];
                  PyObject *ret0=PyDict_New();
                  for(std::map<mcIdType,double>::const_iterator it=row.begin();it!=row.end();it++)
-                   PyDict_SetItem(ret0,PyInt_FromLong((*it).first),PyFloat_FromDouble((*it).second));
+                   {
+                     std::unique_ptr<PyObject,std::function<void(PyObject*)>> k(PyInt_FromLong((*it).first),[](PyObject *obj) { Py_XDECREF(obj); } ),v(PyFloat_FromDouble((*it).second),[](PyObject *obj) { Py_XDECREF(obj); } );
+                     PyDict_SetItem(ret0,k.get(),v.get());
+                   }
                  PyList_SetItem(ret,i,ret0);
                }
              return ret;