Part: [skip ci] fix memory leaks

+ add convenience function GeometryExtension::copyPyObject()
+ make sure to destroy the clone when leaving getGeometry()
This commit is contained in:
wmayer
2020-12-11 12:05:28 +01:00
parent ea3ecf4054
commit 4a8fac9147
5 changed files with 22 additions and 30 deletions

View File

@@ -248,9 +248,7 @@ PyObject* GeometryPy::getExtensionOfType(PyObject *args)
std::shared_ptr<const GeometryExtension> ext(this->getGeometryPtr()->getExtension(type));
// we create a copy and transfer this copy's memory management responsibility to Python
Py::Tuple tuple;
PyObject* cpy = static_cast<GeometryExtensionPy *>(std::const_pointer_cast<GeometryExtension>(ext)->getPyObject())->copy(tuple.ptr());
PyObject* cpy = ext->copyPyObject();
return cpy;
}
catch(const Base::ValueError& e) {
@@ -287,9 +285,7 @@ PyObject* GeometryPy::getExtensionOfName(PyObject *args)
std::shared_ptr<const GeometryExtension> ext(this->getGeometryPtr()->getExtension(std::string(o)));
// we create a copy and transfer this copy's memory management responsibility to Python
Py::Tuple tuple;
PyObject* cpy = static_cast<GeometryExtensionPy *>(std::const_pointer_cast<GeometryExtension>(ext)->getPyObject())->copy(tuple.ptr());
PyObject* cpy = ext->copyPyObject();
return cpy;
}
catch(const Base::ValueError& e) {
@@ -427,9 +423,7 @@ PyObject* GeometryPy::getExtensions(PyObject *args)
// we create a python copy and add it to the list
try {
Py::Tuple tuple;
PyObject* cpy = static_cast<GeometryExtensionPy *>(p->getPyObject())->copy(tuple.ptr());
PyObject* cpy = p->copyPyObject();
PyList_Append( list, cpy);
Py_DECREF(cpy);
}