From 2596eb46b615d18c6a09ff465839fad050b01b42 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 6 Feb 2022 19:47:44 +0100 Subject: [PATCH] Fix cleaning up things when a setup fails in python plugins --- libnymea-core/integrations/pythonintegrationplugin.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libnymea-core/integrations/pythonintegrationplugin.cpp b/libnymea-core/integrations/pythonintegrationplugin.cpp index 306f5f8d..3addd3b4 100644 --- a/libnymea-core/integrations/pythonintegrationplugin.cpp +++ b/libnymea-core/integrations/pythonintegrationplugin.cpp @@ -544,6 +544,7 @@ void PythonIntegrationPlugin::setupThing(ThingSetupInfo *info) connect(info->thing(), &Thing::destroyed, this, [=](){ PyEval_RestoreThread(m_threadState); + m_things.remove(thing); // In case thingRemoved is never called (e.g. failed setup) it needs to be removed too pyThing->thing = nullptr; Py_DECREF(pyThing); m_threadPool->setMaxThreadCount(m_threadPool->maxThreadCount() - 1); @@ -598,7 +599,7 @@ void PythonIntegrationPlugin::executeAction(ThingActionInfo *info) void PythonIntegrationPlugin::thingRemoved(Thing *thing) { - PyThing *pyThing = m_things.take(thing); + PyThing *pyThing = m_things.take(thing); // removing thing from myThings() before the thingRemoved call callPluginFunction("thingRemoved", reinterpret_cast(pyThing)); }