From 867e4507cca9d490e1e1389e3327c97028575c44 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sat, 22 Mar 2025 21:44:17 -0500 Subject: [PATCH] App: Prevent exceptions in destructors Coverity issues 251332 and 356538. These destructors call methods that could throw exceptions. Catch them and convert to console print statements to prevent calls to `terminate()`. --- src/App/PropertyLinks.cpp | 6 +++++- src/App/PropertyPythonObject.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index 75b9d6464b..356f1677d3 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -3731,7 +3731,11 @@ PropertyXLink::PropertyXLink(bool _allowPartial, PropertyLinkBase* parent) PropertyXLink::~PropertyXLink() { - unlink(); + try { + unlink(); + } catch (std::bad_weak_ptr &) { + FC_WARN("Bad pointer exception caught when destroying PropertyXLink\n"); + } } void PropertyXLink::setSyncSubObject(bool enable) diff --git a/src/App/PropertyPythonObject.cpp b/src/App/PropertyPythonObject.cpp index 4141c022d6..935abd69fd 100644 --- a/src/App/PropertyPythonObject.cpp +++ b/src/App/PropertyPythonObject.cpp @@ -48,7 +48,11 @@ PropertyPythonObject::~PropertyPythonObject() // this is needed because the release of the pickled object may need the // GIL. Thus, we grab the GIL and replace the pickled with an empty object Base::PyGILStateLocker lock; - this->object = Py::Object(); + try { + this->object = Py::Object(); + } catch (Py::TypeError &) { + Base::Console().Warning("Py::TypeError Exception caught while destroying PropertyPythonObject\n"); + } } void PropertyPythonObject::setValue(const Py::Object& py)