]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
tests: Don't use the same variable for call and reply
authorSimon McVittie <smcv@collabora.com>
Tue, 21 Nov 2017 11:59:20 +0000 (11:59 +0000)
committerSimon McVittie <smcv@collabora.com>
Fri, 24 Nov 2017 12:19:12 +0000 (12:19 +0000)
It seemed like a nice idea at the time, but I now think it's more
confusing than it's worth.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103600

test/dbus-daemon.c
test/monitor.c
test/sd-activation.c
test/uid-permissions.c

index ce8edc8221ac7e011b62c1d6e03a833e92fe594a..8d6d65dd0b4da73f86e787b96b477add44ce40a4 100644 (file)
@@ -385,6 +385,7 @@ test_creds (Fixture *f,
   const char *unique = dbus_bus_get_unique_name (f->left_conn);
   DBusMessage *m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
       DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "GetConnectionCredentials");
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc;
   DBusMessageIter args_iter;
   DBusMessageIter arr_iter;
@@ -410,20 +411,18 @@ test_creds (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  g_assert_cmpstr (dbus_message_get_signature (m), ==, "a{sv}");
+  g_assert_cmpstr (dbus_message_get_signature (reply), ==, "a{sv}");
 
-  dbus_message_iter_init (m, &args_iter);
+  dbus_message_iter_init (reply, &args_iter);
   g_assert_cmpuint (dbus_message_iter_get_arg_type (&args_iter), ==,
       DBUS_TYPE_ARRAY);
   g_assert_cmpuint (dbus_message_iter_get_element_type (&args_iter), ==,
@@ -535,6 +534,7 @@ test_creds (Fixture *f,
   g_assert (seen & SEEN_WINDOWS_SID);
 #endif
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -546,6 +546,7 @@ test_processid (Fixture *f,
   const char *unique = dbus_bus_get_unique_name (f->left_conn);
   DBusMessage *m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
       DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "GetConnectionUnixProcessID");
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc;
   DBusError error = DBUS_ERROR_INIT;
   guint32 pid;
@@ -563,18 +564,16 @@ test_processid (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (dbus_set_error_from_message (&error, m))
+  if (dbus_set_error_from_message (&error, reply))
     {
       g_assert_cmpstr (error.name, ==, DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN);
 
@@ -585,11 +584,11 @@ test_processid (Fixture *f,
 
       dbus_error_free (&error);
     }
-  else if (dbus_message_get_args (m, &error,
+  else if (dbus_message_get_args (reply, &error,
         DBUS_TYPE_UINT32, &pid,
         DBUS_TYPE_INVALID))
     {
-      g_assert_cmpstr (dbus_message_get_signature (m), ==, "u");
+      g_assert_cmpstr (dbus_message_get_signature (reply), ==, "u");
       test_assert_no_error (&error);
 
       g_test_message ("GetConnectionUnixProcessID returned %u", pid);
@@ -607,6 +606,7 @@ test_processid (Fixture *f,
       g_error ("Unexpected error: %s: %s", error.name, error.message);
     }
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -617,6 +617,7 @@ test_canonical_path_uae (Fixture *f,
 {
   DBusMessage *m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
       DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "UpdateActivationEnvironment");
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc;
   DBusMessageIter args_iter;
   DBusMessageIter arr_iter;
@@ -637,21 +638,20 @@ test_canonical_path_uae (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
   /* it succeeds */
-  g_assert_cmpint (dbus_message_get_type (m), ==,
+  g_assert_cmpint (dbus_message_get_type (reply), ==,
       DBUS_MESSAGE_TYPE_METHOD_RETURN);
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 
@@ -675,23 +675,22 @@ test_canonical_path_uae (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
   /* it fails, yielding an error message with one string argument */
-  g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
-  g_assert_cmpstr (dbus_message_get_error_name (m), ==,
+  g_assert_cmpint (dbus_message_get_type (reply), ==, DBUS_MESSAGE_TYPE_ERROR);
+  g_assert_cmpstr (dbus_message_get_error_name (reply), ==,
       DBUS_ERROR_ACCESS_DENIED);
-  g_assert_cmpstr (dbus_message_get_signature (m), ==, "s");
+  g_assert_cmpstr (dbus_message_get_signature (reply), ==, "s");
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -1193,6 +1192,7 @@ test_peer_get_machine_id (Fixture *f,
   char *what_i_think;
   const char *what_daemon_thinks;
   DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc = NULL;
   DBusError error = DBUS_ERROR_INIT;
 
@@ -1229,18 +1229,16 @@ test_peer_get_machine_id (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (!dbus_message_get_args (m, &error,
+  if (!dbus_message_get_args (reply, &error,
         DBUS_TYPE_STRING, &what_daemon_thinks,
         DBUS_TYPE_INVALID))
     g_error ("%s: %s", error.name, error.message);
@@ -1249,6 +1247,7 @@ test_peer_get_machine_id (Fixture *f,
   g_assert_nonnull (what_daemon_thinks);
   g_assert_cmpuint (strlen (what_daemon_thinks), ==, 32);
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
   dbus_free (what_i_think);
@@ -1259,6 +1258,7 @@ test_peer_ping (Fixture *f,
                 gconstpointer context)
 {
   DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc = NULL;
   DBusError error = DBUS_ERROR_INIT;
 
@@ -1274,20 +1274,19 @@ test_peer_ping (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (!dbus_message_get_args (m, &error, DBUS_TYPE_INVALID))
+  if (!dbus_message_get_args (reply, &error, DBUS_TYPE_INVALID))
     g_error ("%s: %s", error.name, error.message);
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -1297,6 +1296,7 @@ test_get_invalid_path (Fixture *f,
                        gconstpointer context)
 {
   DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc = NULL;
   DBusError error = DBUS_ERROR_INIT;
   const char *iface = DBUS_INTERFACE_DBUS;
@@ -1318,24 +1318,23 @@ test_get_invalid_path (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (!dbus_set_error_from_message (&error, m))
+  if (!dbus_set_error_from_message (&error, reply))
     g_error ("Unexpected success");
 
   /* That object path does not have that interface */
   g_assert_cmpstr (error.name, ==, DBUS_ERROR_UNKNOWN_INTERFACE);
   dbus_error_free (&error);
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -1345,6 +1344,7 @@ test_get_invalid_iface (Fixture *f,
                         gconstpointer context)
 {
   DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc = NULL;
   DBusError error = DBUS_ERROR_INIT;
   const char *iface = "com.example.Nope";
@@ -1366,23 +1366,22 @@ test_get_invalid_iface (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (!dbus_set_error_from_message (&error, m))
+  if (!dbus_set_error_from_message (&error, reply))
     g_error ("Unexpected success");
 
   g_assert_cmpstr (error.name, ==, DBUS_ERROR_UNKNOWN_INTERFACE);
   dbus_error_free (&error);
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -1392,6 +1391,7 @@ test_get_invalid (Fixture *f,
                   gconstpointer context)
 {
   DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc = NULL;
   DBusError error = DBUS_ERROR_INIT;
   const char *iface = DBUS_INTERFACE_DBUS;
@@ -1413,23 +1413,22 @@ test_get_invalid (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (!dbus_set_error_from_message (&error, m))
+  if (!dbus_set_error_from_message (&error, reply))
     g_error ("Unexpected success");
 
   g_assert_cmpstr (error.name, ==, DBUS_ERROR_UNKNOWN_PROPERTY);
   dbus_error_free (&error);
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -1439,6 +1438,7 @@ test_get_all_invalid_iface (Fixture *f,
                             gconstpointer context)
 {
   DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc = NULL;
   DBusError error = DBUS_ERROR_INIT;
   const char *iface = "com.example.Nope";
@@ -1458,23 +1458,22 @@ test_get_all_invalid_iface (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (!dbus_set_error_from_message (&error, m))
+  if (!dbus_set_error_from_message (&error, reply))
     g_error ("Unexpected success");
 
   g_assert_cmpstr (error.name, ==, DBUS_ERROR_UNKNOWN_INTERFACE);
   dbus_error_free (&error);
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -1484,6 +1483,7 @@ test_get_all_invalid_path (Fixture *f,
                            gconstpointer context)
 {
   DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc = NULL;
   DBusError error = DBUS_ERROR_INIT;
   const char *iface = DBUS_INTERFACE_DBUS;
@@ -1503,24 +1503,23 @@ test_get_all_invalid_path (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (!dbus_set_error_from_message (&error, m))
+  if (!dbus_set_error_from_message (&error, reply))
     g_error ("Unexpected success");
 
   /* That object path does not have that interface */
   g_assert_cmpstr (error.name, ==, DBUS_ERROR_UNKNOWN_INTERFACE);
   dbus_error_free (&error);
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -1530,6 +1529,7 @@ test_set_invalid_iface (Fixture *f,
                         gconstpointer context)
 {
   DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc = NULL;
   DBusError error = DBUS_ERROR_INIT;
   const char *iface = "com.example.Nope";
@@ -1562,23 +1562,22 @@ test_set_invalid_iface (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (!dbus_set_error_from_message (&error, m))
+  if (!dbus_set_error_from_message (&error, reply))
     g_error ("Unexpected success");
 
   g_assert_cmpstr (error.name, ==, DBUS_ERROR_UNKNOWN_INTERFACE);
   dbus_error_free (&error);
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -1588,6 +1587,7 @@ test_set_invalid_path (Fixture *f,
                        gconstpointer context)
 {
   DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc = NULL;
   DBusError error = DBUS_ERROR_INIT;
   const char *iface = DBUS_INTERFACE_DBUS;
@@ -1620,23 +1620,22 @@ test_set_invalid_path (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (!dbus_set_error_from_message (&error, m))
+  if (!dbus_set_error_from_message (&error, reply))
     g_error ("Unexpected success");
 
   g_assert_cmpstr (error.name, ==, DBUS_ERROR_UNKNOWN_INTERFACE);
   dbus_error_free (&error);
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -1646,6 +1645,7 @@ test_set_invalid (Fixture *f,
                   gconstpointer context)
 {
   DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc = NULL;
   DBusError error = DBUS_ERROR_INIT;
   const char *iface = DBUS_INTERFACE_DBUS;
@@ -1678,23 +1678,22 @@ test_set_invalid (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (!dbus_set_error_from_message (&error, m))
+  if (!dbus_set_error_from_message (&error, reply))
     g_error ("Unexpected success");
 
   g_assert_cmpstr (error.name, ==, DBUS_ERROR_UNKNOWN_PROPERTY);
   dbus_error_free (&error);
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -1704,6 +1703,7 @@ test_set (Fixture *f,
           gconstpointer context)
 {
   DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc = NULL;
   DBusError error = DBUS_ERROR_INIT;
   const char *iface = DBUS_INTERFACE_DBUS;
@@ -1736,23 +1736,22 @@ test_set (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (!dbus_set_error_from_message (&error, m))
+  if (!dbus_set_error_from_message (&error, reply))
     g_error ("Unexpected success");
 
   g_assert_cmpstr (error.name, ==, DBUS_ERROR_PROPERTY_READ_ONLY);
   dbus_error_free (&error);
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -1800,6 +1799,7 @@ test_features (Fixture *f,
                gconstpointer context)
 {
   DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc = NULL;
   DBusMessageIter args_iter;
   DBusMessageIter var_iter;
@@ -1822,18 +1822,16 @@ test_features (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (!dbus_message_iter_init (m, &args_iter))
+  if (!dbus_message_iter_init (reply, &args_iter))
     g_error ("Reply has no arguments");
 
   g_assert_cmpint (dbus_message_iter_get_arg_type (&args_iter), ==,
@@ -1845,6 +1843,7 @@ test_features (Fixture *f,
   if (dbus_message_iter_next (&args_iter))
     g_error ("Reply has too many arguments");
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -1907,6 +1906,7 @@ test_interfaces (Fixture *f,
                  gconstpointer context)
 {
   DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc = NULL;
   DBusMessageIter args_iter;
   DBusMessageIter var_iter;
@@ -1929,18 +1929,16 @@ test_interfaces (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (!dbus_message_iter_init (m, &args_iter))
+  if (!dbus_message_iter_init (reply, &args_iter))
     g_error ("Reply has no arguments");
 
   if (dbus_message_iter_get_arg_type (&args_iter) != DBUS_TYPE_VARIANT)
@@ -1952,6 +1950,7 @@ test_interfaces (Fixture *f,
   if (dbus_message_iter_next (&args_iter))
     g_error ("Reply has too many arguments");
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
@@ -1961,6 +1960,7 @@ test_get_all (Fixture *f,
               gconstpointer context)
 {
   DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc = NULL;
   DBusMessageIter args_iter;
   DBusMessageIter arr_iter;
@@ -1985,18 +1985,16 @@ test_get_all (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_clear_message (&m);
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  dbus_message_iter_init (m, &args_iter);
+  dbus_message_iter_init (reply, &args_iter);
   g_assert_cmpuint (dbus_message_iter_get_arg_type (&args_iter), ==,
       DBUS_TYPE_ARRAY);
   g_assert_cmpuint (dbus_message_iter_get_element_type (&args_iter), ==,
@@ -2036,6 +2034,7 @@ test_get_all (Fixture *f,
   if (dbus_message_iter_next (&args_iter))
     g_error ("Reply has too many arguments");
 
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
   dbus_clear_pending_call (&pc);
 }
index df5a7180ef1e64b43d0a31cbf189892bfd217497..55d615982d4cb3a15581fc5cf5fc62b67bdd4865 100644 (file)
@@ -497,7 +497,8 @@ static void
 become_monitor (Fixture *f,
     const Config *config)
 {
-  DBusMessage *m;
+  DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
   DBusPendingCall *pc;
   dbus_bool_t ok;
   DBusMessageIter appender, array_appender;
@@ -543,26 +544,23 @@ become_monitor (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_message_unref (m);
-  m = NULL;
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-        &m, NULL))
+        &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  ok = dbus_message_get_args (m, &f->e,
+  ok = dbus_message_get_args (reply, &f->e,
       DBUS_TYPE_INVALID);
   test_assert_no_error (&f->e);
   g_assert (ok);
 
-  dbus_pending_call_unref (pc);
-  dbus_message_unref (m);
-  m = NULL;
+  dbus_clear_pending_call (&pc);
+  dbus_clear_message (&reply);
+  dbus_clear_message (&m);
 }
 
 /*
@@ -572,8 +570,9 @@ static void
 test_invalid (Fixture *f,
     gconstpointer context)
 {
-  DBusMessage *m;
-  DBusPendingCall *pc;
+  DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
+  DBusPendingCall *pc = NULL;
   dbus_bool_t ok;
   DBusMessageIter appender, array_appender;
   dbus_uint32_t zero = 0;
@@ -609,28 +608,26 @@ test_invalid (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_message_unref (m);
-  m = NULL;
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-        &m, NULL))
+        &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
-  g_assert_cmpstr (dbus_message_get_error_name (m), ==,
+  g_assert_cmpint (dbus_message_get_type (reply), ==, DBUS_MESSAGE_TYPE_ERROR);
+  g_assert_cmpstr (dbus_message_get_error_name (reply), ==,
       DBUS_ERROR_INVALID_ARGS);
 
+  dbus_clear_pending_call (&pc);
+  dbus_clear_message (&reply);
+  dbus_clear_message (&m);
+
   /* Try to become a monitor but use the wrong object path - not allowed
    * (security hardening against inappropriate XML policy rules) */
 
-  dbus_pending_call_unref (pc);
-  dbus_message_unref (m);
-
   m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
       "/", DBUS_INTERFACE_MONITORING, "BecomeMonitor");
 
@@ -652,28 +649,26 @@ test_invalid (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_message_unref (m);
-  m = NULL;
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-        &m, NULL))
+        &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
-  g_assert_cmpstr (dbus_message_get_error_name (m), ==,
+  g_assert_cmpint (dbus_message_get_type (reply), ==, DBUS_MESSAGE_TYPE_ERROR);
+  g_assert_cmpstr (dbus_message_get_error_name (reply), ==,
       DBUS_ERROR_UNKNOWN_INTERFACE);
 
+  dbus_clear_pending_call (&pc);
+  dbus_clear_message (&reply);
+  dbus_clear_message (&m);
+
   /* Try to become a monitor but specify a bad match rule -
    * also not allowed */
 
-  dbus_pending_call_unref (pc);
-  dbus_message_unref (m);
-
   m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
       DBUS_PATH_DBUS, DBUS_INTERFACE_MONITORING, "BecomeMonitor");
 
@@ -700,28 +695,25 @@ test_invalid (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_message_unref (m);
-  m = NULL;
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-        &m, NULL))
+        &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
-  g_assert_cmpstr (dbus_message_get_error_name (m), ==,
+  g_assert_cmpint (dbus_message_get_type (reply), ==, DBUS_MESSAGE_TYPE_ERROR);
+  g_assert_cmpstr (dbus_message_get_error_name (reply), ==,
       DBUS_ERROR_MATCH_RULE_INVALID);
 
-  dbus_pending_call_unref (pc);
-  dbus_message_unref (m);
+  dbus_clear_pending_call (&pc);
+  dbus_clear_message (&reply);
+  dbus_clear_message (&m);
 
   /* We did not become a monitor, so we can still call methods. */
 
-  pc = NULL;
   m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
       DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "GetId");
 
@@ -733,22 +725,19 @@ test_invalid (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_message_unref (m);
-  m = NULL;
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-        &m, NULL))
+        &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  if (dbus_set_error_from_message (&f->e, m))
+  if (dbus_set_error_from_message (&f->e, reply))
     g_error ("%s: %s", f->e.name, f->e.message);
 
-  ok = dbus_message_get_args (m, &f->e,
+  ok = dbus_message_get_args (reply, &f->e,
       DBUS_TYPE_STRING, &s,
       DBUS_TYPE_INVALID);
   test_assert_no_error (&f->e);
@@ -756,8 +745,9 @@ test_invalid (Fixture *f,
   g_assert_cmpstr (s, !=, NULL);
   g_assert_cmpstr (s, !=, "");
 
-  dbus_pending_call_unref (pc);
-  dbus_message_unref (m);
+  dbus_clear_pending_call (&pc);
+  dbus_clear_message (&reply);
+  dbus_clear_message (&m);
 }
 
 /*
index bf6f8b6fb5bee184e98f471553b244749c24b400..c8e412256a9d7dbfe32aec72f8c1b4eecbc812de 100644 (file)
@@ -522,8 +522,9 @@ static void
 test_uae (Fixture *f,
     gconstpointer context)
 {
-  DBusMessage *m;
-  DBusPendingCall *pc;
+  DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
+  DBusPendingCall *pc = NULL;
   DBusMessageIter args_iter, arr_iter, entry_iter;
   const char *s;
 
@@ -548,21 +549,19 @@ test_uae (Fixture *f,
         DBUS_TIMEOUT_USE_DEFAULT) || pc == NULL)
     g_error ("OOM");
 
-  dbus_message_unref (m);
-  m = NULL;
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-        &m, NULL))
+        &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  assert_method_reply (m, DBUS_SERVICE_DBUS, f->caller_name, "");
+  assert_method_reply (reply, DBUS_SERVICE_DBUS, f->caller_name, "");
 
   dbus_clear_pending_call (&pc);
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
 
   /* The fake systemd connects to the bus. */
@@ -635,21 +634,19 @@ test_uae (Fixture *f,
         DBUS_TIMEOUT_USE_DEFAULT) || pc == NULL)
     g_error ("OOM");
 
-  dbus_message_unref (m);
-  m = NULL;
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-        &m, NULL))
+        &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
-  assert_method_reply (m, DBUS_SERVICE_DBUS, f->caller_name, "");
+  assert_method_reply (reply, DBUS_SERVICE_DBUS, f->caller_name, "");
 
   dbus_clear_pending_call (&pc);
+  dbus_clear_message (&reply);
   dbus_clear_message (&m);
 
   while (f->systemd_message == NULL)
@@ -884,24 +881,22 @@ test_transient_services (Fixture *f,
             DBUS_TIMEOUT_USE_DEFAULT) || pc == NULL)
         g_error ("OOM");
 
-      dbus_message_unref (m);
-      m = NULL;
-
       /* It fails. */
 
       if (dbus_pending_call_get_completed (pc))
-        test_pending_call_store_reply (pc, &m);
+        test_pending_call_store_reply (pc, &reply);
       else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-            &m, NULL))
+            &reply, NULL))
         g_error ("OOM");
 
-      while (m == NULL)
+      while (reply == NULL)
         test_main_context_iterate (f->ctx, TRUE);
 
-      assert_error_reply (m, DBUS_SERVICE_DBUS, f->caller_name,
+      assert_error_reply (reply, DBUS_SERVICE_DBUS, f->caller_name,
           DBUS_ERROR_SERVICE_UNKNOWN);
 
       dbus_clear_pending_call (&pc);
+      dbus_clear_message (&reply);
       dbus_clear_message (&m);
 
       /* Now generate a transient D-Bus service file for it. The directory
@@ -919,21 +914,19 @@ test_transient_services (Fixture *f,
             DBUS_TIMEOUT_USE_DEFAULT) || pc == NULL)
         g_error ("OOM");
 
-      dbus_message_unref (m);
-      m = NULL;
-
       if (dbus_pending_call_get_completed (pc))
-        test_pending_call_store_reply (pc, &m);
+        test_pending_call_store_reply (pc, &reply);
       else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-            &m, NULL))
+            &reply, NULL))
         g_error ("OOM");
 
-      while (m == NULL)
+      while (reply == NULL)
         test_main_context_iterate (f->ctx, TRUE);
 
-      assert_method_reply (m, DBUS_SERVICE_DBUS, f->caller_name, "");
+      assert_method_reply (reply, DBUS_SERVICE_DBUS, f->caller_name, "");
 
       dbus_clear_pending_call (&pc);
+      dbus_clear_message (&reply);
       dbus_clear_message (&m);
     }
 
index ce6d7a6b2a8481741d335cc44f160092affbde3c..6ccb1767c891cdc80e730982ba55734d907100e5 100644 (file)
@@ -91,8 +91,9 @@ test_uae (Fixture *f,
     gconstpointer context)
 {
   const Config *config = context;
-  DBusMessage *m;
-  DBusPendingCall *pc;
+  DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
+  DBusPendingCall *pc = NULL;
   DBusMessageIter args_iter;
   DBusMessageIter arr_iter;
 
@@ -118,35 +119,33 @@ test_uae (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_message_unref (m);
-  m = NULL;
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
   if (config->expect_success)
     {
       /* it succeeds */
-      g_assert_cmpint (dbus_message_get_type (m), ==,
+      g_assert_cmpint (dbus_message_get_type (reply), ==,
           DBUS_MESSAGE_TYPE_METHOD_RETURN);
     }
   else
     {
       /* it fails, yielding an error message with one string argument */
-      g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
-      g_assert_cmpstr (dbus_message_get_error_name (m), ==,
+      g_assert_cmpint (dbus_message_get_type (reply), ==, DBUS_MESSAGE_TYPE_ERROR);
+      g_assert_cmpstr (dbus_message_get_error_name (reply), ==,
           DBUS_ERROR_ACCESS_DENIED);
-      g_assert_cmpstr (dbus_message_get_signature (m), ==, "s");
+      g_assert_cmpstr (dbus_message_get_signature (reply), ==, "s");
     }
 
   dbus_clear_pending_call (&pc);
-  dbus_message_unref (m);
+  dbus_clear_message (&reply);
+  dbus_clear_message (&m);
 }
 
 static void
@@ -154,8 +153,9 @@ test_monitor (Fixture *f,
     gconstpointer context)
 {
   const Config *config = context;
-  DBusMessage *m;
-  DBusPendingCall *pc;
+  DBusMessage *m = NULL;
+  DBusMessage *reply = NULL;
+  DBusPendingCall *pc = NULL;
   DBusMessageIter args_iter;
   DBusMessageIter arr_iter;
   dbus_uint32_t no_flags = 0;
@@ -184,35 +184,33 @@ test_monitor (Fixture *f,
       pc == NULL)
     g_error ("OOM");
 
-  dbus_message_unref (m);
-  m = NULL;
-
   if (dbus_pending_call_get_completed (pc))
-    test_pending_call_store_reply (pc, &m);
+    test_pending_call_store_reply (pc, &reply);
   else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
-                                          &m, NULL))
+                                          &reply, NULL))
     g_error ("OOM");
 
-  while (m == NULL)
+  while (reply == NULL)
     test_main_context_iterate (f->ctx, TRUE);
 
   if (config->expect_success)
     {
       /* it succeeds */
-      g_assert_cmpint (dbus_message_get_type (m), ==,
+      g_assert_cmpint (dbus_message_get_type (reply), ==,
           DBUS_MESSAGE_TYPE_METHOD_RETURN);
     }
   else
     {
       /* it fails, yielding an error message with one string argument */
-      g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
-      g_assert_cmpstr (dbus_message_get_error_name (m), ==,
+      g_assert_cmpint (dbus_message_get_type (reply), ==, DBUS_MESSAGE_TYPE_ERROR);
+      g_assert_cmpstr (dbus_message_get_error_name (reply), ==,
           DBUS_ERROR_ACCESS_DENIED);
-      g_assert_cmpstr (dbus_message_get_signature (m), ==, "s");
+      g_assert_cmpstr (dbus_message_get_signature (reply), ==, "s");
     }
 
   dbus_clear_pending_call (&pc);
-  dbus_message_unref (m);
+  dbus_clear_message (&reply);
+  dbus_clear_message (&m);
 }
 
 static void