]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- fixed object lifetime 814/head
authorArvin Schnell <aschnell@suse.de>
Wed, 26 Apr 2023 08:23:36 +0000 (10:23 +0200)
committerArvin Schnell <aschnell@suse.de>
Wed, 26 Apr 2023 08:23:36 +0000 (10:23 +0200)
dbus/DBusConnection.cc
dbus/DBusMessage.h

index 74fb7f4426adb84aaa2f427f3e7f959fb180a8f3..5c6e873e714814b2395fddfda25c90e37caf0d7c 100644 (file)
@@ -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;
index b54e5f34710ac5a4fdfe40bfd07ca7fcffccafbf..39ca483091c94a2073a515884c0c9cb6896884a3 100644 (file)
@@ -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;
     };