summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Lorenz <jlorenz@de.adit-jv.com>2018-02-05 17:29:44 +0100
committerJens Lorenz <jlorenz@de.adit-jv.com>2018-02-05 17:29:44 +0100
commita551ce940f073a7a2afa7df104b9eabc99e9f4a2 (patch)
treed4ad33212f782cb2c0665f1e9d9d7e83cfc24984
parentc60d46d3f97dcf185f1716388eaa3907c2e545e5 (diff)
downloadaudiomanager-a551ce940f073a7a2afa7df104b9eabc99e9f4a2.tar.gz
AmUtil: Check for valid timer handles to fix callback exception
In case plugins remove dbus timer callbacks at runtime a race might happen between the deletion of timer and the callback invocation. Now the timer callback function checks if the timer is valid before proceeding with the restart. Signed-off-by: Kapildev Patel <kpatel@jp.adit-jv.com>
-rw-r--r--AudioManagerUtilities/src/CAmDbusWrapper.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/AudioManagerUtilities/src/CAmDbusWrapper.cpp b/AudioManagerUtilities/src/CAmDbusWrapper.cpp
index 1f1d5a6..e25439c 100644
--- a/AudioManagerUtilities/src/CAmDbusWrapper.cpp
+++ b/AudioManagerUtilities/src/CAmDbusWrapper.cpp
@@ -176,7 +176,6 @@ void CAmDbusWrapper::registerCallback(const DBusObjectPathVTable* vtable, const
std::string completePath = prefix + "/" + path;
dbus_error_init(&mDBusError);
- mpDbusConnection = dbus_bus_get(mDbusType, &mDBusError);
dbus_connection_register_object_path(mpDbusConnection, completePath.c_str(), vtable, userdata);
if (dbus_error_is_set(&mDBusError))
{
@@ -196,7 +195,6 @@ void CAmDbusWrapper::registerSignalWatch(DBusHandleMessageFunction handler, cons
{
logInfo("DBusWrapper::registerSignalWatch register callback:", rule);
dbus_error_init(&mDBusError);
- mpDbusConnection = dbus_bus_get(mDbusType, &mDBusError);
dbus_bus_add_match(mpDbusConnection, rule.c_str(), &mDBusError);
dbus_connection_flush(mpDbusConnection);
dbus_connection_add_filter(mpDbusConnection, handler, userdata, 0);
@@ -389,8 +387,6 @@ dbus_bool_t CAmDbusWrapper::addTimeoutDelegate(DBusTimeout *timeout, void* userD
//save the handle with dbus context
dbus_timeout_set_data(timeout, handle, NULL);
- //save timeout in Socket context
- userData = timeout;
return (true);
}
@@ -516,11 +512,19 @@ void CAmDbusWrapper::toggleTimeoutDelegate(DBusTimeout *timeout, void* userData)
void CAmDbusWrapper::dbusTimerCallback(sh_timerHandle_t handle, void *userData)
{
assert(userData!=NULL);
- if (dbus_timeout_get_enabled((DBusTimeout*) userData))
+ for (auto && timerHandle : mpListTimerhandles)
{
- mpSocketHandler->restartTimer(handle);
+ if (*timerHandle == handle)
+ {
+ if (dbus_timeout_get_enabled((DBusTimeout*) userData))
+ {
+ mpSocketHandler->restartTimer(handle);
+ }
+ dbus_timeout_handle((DBusTimeout*) userData);
+ return;
+ }
}
- dbus_timeout_handle((DBusTimeout*) userData);
+ logWarning("CAmDbusWrapper::dbusTimerCallback Unknown timer handle");
}
}