From: Michal Szczecinski Date: Wed, 5 Mar 2025 07:04:12 +0000 (+0100) Subject: Dbus: added exception handlers in destructors. X-Git-Tag: accepted/tizen/unified/x/20250312.134154^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=701dd98e75ffa2dc96cf2a9ceb6631ac8c8850dc;p=profile%2Fcommon%2Fapps%2Fnative%2Faccessibility-setting.git Dbus: added exception handlers in destructors. To avoid std::terminate() in case of exception in destructor, this patch adds exception handlers. Now instead of terminating application, an error will be printed. Change-Id: Ia5db61559b649df8eb1803ef730c518e96e9f283 --- diff --git a/src/service/DBus.cpp b/src/service/DBus.cpp index 2a8e343..6aacf2f 100644 --- a/src/service/DBus.cpp +++ b/src/service/DBus.cpp @@ -242,9 +242,13 @@ struct DefaultDBusWrapper : public DBusWrapper ProxyImpl(Eldbus_Proxy *Value, bool EraseOnExit = false) : Value(Value), EraseOnExit(EraseOnExit) {} ~ProxyImpl() { - for (auto &it : destructors) - if (it) - it(); + try { + for (auto &it : destructors) + if (it) + it(); + } catch (...) { + DBUS_DEBUG("ProxyImpl: Exception in destructor"); + } } }; DEFINE_GS(Proxy, Eldbus_Proxy, ) @@ -756,8 +760,13 @@ OwnerNameCallbackHandle &OwnerNameCallbackHandle::operator=(OwnerNameCallbackHan OwnerNameCallbackHandle::~OwnerNameCallbackHandle() { - if (callback_) - callback_(); + try { + if (callback_) { + callback_(); + } + } catch (...) { + DBUS_DEBUG("Exception in OwnerNameCallbackHandle destructor"); + } } OwnerNameCallbackHandle DBus::registerNameOwnerChangedCallback(DBusWrapper::ConnectionPtr connection, const std::string &bus, std::function fnc_) diff --git a/src/service/DBus.hpp b/src/service/DBus.hpp index 70d6d87..cb9b076 100644 --- a/src/service/DBus.hpp +++ b/src/service/DBus.hpp @@ -498,7 +498,11 @@ namespace DBus } const char *what() const noexcept override { - text = temp->str(); + try { + text = temp->str(); + } catch (...) { + return "Exception information is not available due to memory allocation issue"; + } return text.c_str(); } }; @@ -3408,8 +3412,12 @@ namespace DBus std::vector> destructors; ~DestructorObject() { - for (auto &a : destructors) - a(); + try { + for (auto &a : destructors) + a(); + } catch (...) { + DBUS_DEBUG("Fatal issue: unhandled exception in destructor"); + } } }; std::unique_ptr destructorObject{new DestructorObject()};