From 8082e8da9e23478adf41d195bb6f74f938d9f04d Mon Sep 17 00:00:00 2001 From: Radoslaw Cybulski Date: Thu, 5 Oct 2017 11:58:19 +0200 Subject: [PATCH] Fix for invalid signal deregistration Add signal hanlder unregister call, when pointer to callback function is being destroyed. Change-Id: I379f988a2589bd06fc95297a3ed6df32deefdc3b --- src/DBus.hpp | 3 ++- tests/no-ui-scenarios/DBusTests.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/DBus.hpp b/src/DBus.hpp index 954f62c..6c7b727 100644 --- a/src/DBus.hpp +++ b/src/DBus.hpp @@ -1110,8 +1110,9 @@ namespace DBus detail::apply(callback, params.getValues()); } }; - eldbus_proxy_signal_handler_add(connectionState.proxy, signalName.c_str(), listenerCallback, tmp); + auto handler = eldbus_proxy_signal_handler_add(connectionState.proxy, signalName.c_str(), listenerCallback, tmp); destructors.push_back([ = ]() { + eldbus_signal_handler_del(handler); delete tmp; }); } diff --git a/tests/no-ui-scenarios/DBusTests.cpp b/tests/no-ui-scenarios/DBusTests.cpp index 7cc02e9..09c6b43 100644 --- a/tests/no-ui-scenarios/DBusTests.cpp +++ b/tests/no-ui-scenarios/DBusTests.cpp @@ -539,7 +539,14 @@ TEST_F(DBusTest, synchronousCall) auto r = db.method("add").call(10, 55); ASSERT_TRUE(r); ASSERT_EQ(std::get<0>(r), 10 + 55); - r = db.method("add").call(-10, 55); +} + +// Calls method on external process synchronously, expect error +TEST_F(DBusTest, synchronousCallExpectError) +{ + auto connection = DBus::getDBusConnectionByType(DBus::ConnectionType::SYSTEM); + DBus::DBusClient db{testBusName, syncPathName, syncInterfaceName, connection}; + auto r = db.method("add").call(-10, 55); ASSERT_FALSE(r); ASSERT_EQ(r.getError().message, "org.freedesktop.DBus.Error.Failed: negative"); } -- 2.7.4