From: Arvin Schnell Date: Wed, 26 Apr 2023 08:23:36 +0000 (+0200) Subject: - fixed object lifetime X-Git-Tag: v0.10.5~7^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F814%2Fhead;p=thirdparty%2Fsnapper.git - fixed object lifetime --- diff --git a/dbus/DBusConnection.cc b/dbus/DBusConnection.cc index 74fb7f44..5c6e873e 100644 --- a/dbus/DBusConnection.cc +++ b/dbus/DBusConnection.cc @@ -1,5 +1,6 @@ /* * Copyright (c) 2012 Novell, Inc. + * Copyright (c) 2023 SUSE LLC * * All Rights Reserved. * @@ -39,8 +40,7 @@ namespace DBus conn = dbus_bus_get(type, &err); if (dbus_error_is_set(&err)) { - dbus_error_free(&err); - SN_THROW(FatalException()); + SN_THROW(ErrorException(&err)); } if (!conn) @@ -67,8 +67,7 @@ namespace DBus int ret = dbus_bus_request_name(conn, name, flags, &err); if (dbus_error_is_set(&err)) { - dbus_error_free(&err); - SN_THROW(FatalException()); + SN_THROW(ErrorException(&err)); } if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) @@ -102,7 +101,7 @@ namespace DBus 0x7fffffff, &err); if (dbus_error_is_set(&err)) { - SN_THROW(ErrorException(err)); + SN_THROW(ErrorException(&err)); } return Message(tmp, false); @@ -168,8 +167,7 @@ namespace DBus unsigned long uid = dbus_bus_get_unix_user(conn, sender.c_str(), &err); if (dbus_error_is_set(&err)) { - dbus_error_free(&err); - SN_THROW(FatalException()); + SN_THROW(ErrorException(&err)); } return uid; diff --git a/dbus/DBusMessage.h b/dbus/DBusMessage.h index b54e5f34..39ca4830 100644 --- a/dbus/DBusMessage.h +++ b/dbus/DBusMessage.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2012 Novell, Inc. - * Copyright (c) 2016 SUSE LLC + * Copyright (c) [2016-2023] SUSE LLC * * All Rights Reserved. * @@ -54,12 +54,17 @@ namespace DBus struct ErrorException : public Exception { - explicit ErrorException(const DBusError err) - : Exception("dbus error exception"), err(err) {} - virtual ~ErrorException() { dbus_error_free(&err); } - virtual const char* name() const { return err.name; } - virtual const char* message() const { return err.message; } - DBusError err; + explicit ErrorException(DBusError* err) + : Exception("dbus error exception"), err_name(err->name), err_message(err->message) + { + dbus_error_free(err); + } + + const char* name() const { return err_name.c_str(); } + const char* message() const { return err_message.c_str(); } + + const string err_name; + const string err_message; };