GDBus CXX (dbus-1 and gio): avoid uninitialized memory access in SignalWatch

If the watch was never activated, m_tag was never set, which led to an
invalid memory read in the destructor. Also be more careful with using
the connection and better check that it still exists.
This commit is contained in:
Patrick Ohly 2011-11-30 15:05:22 +00:00
parent ad513df9cd
commit 379ecd7d78
2 changed files with 10 additions and 4 deletions

View file

@ -4088,14 +4088,17 @@ template <class T> class SignalWatch
public:
SignalWatch(const DBusRemoteObject &object,
const std::string &signal)
: m_object(object), m_signal(signal)
: m_object(object), m_signal(signal), m_tag(0)
{
}
~SignalWatch()
{
if (m_tag) {
b_dbus_remove_watch(m_object.getConnection(), m_tag);
DBusConnection *connection = m_object.getConnection();
if (connection) {
b_dbus_remove_watch(connection, m_tag);
}
}
}

View file

@ -4069,14 +4069,17 @@ template <class T> class SignalWatch
public:
SignalWatch(const DBusRemoteObject &object,
const std::string &signal)
: m_object(object), m_signal(signal)
: m_object(object), m_signal(signal), m_tag(0)
{
}
~SignalWatch()
{
if (m_tag) {
g_dbus_connection_signal_unsubscribe(m_object.getConnection(), m_tag);
GDBusConnection *connection = m_object.getConnection();
if (connection) {
g_dbus_connection_signal_unsubscribe(connection, m_tag);
}
}
}