test/loopback: Don't leak address strings
authorSimon McVittie <smcv@collabora.com>
Wed, 28 Jun 2017 17:49:18 +0000 (18:49 +0100)
committerSimon McVittie <smcv@collabora.com>
Thu, 29 Jun 2017 13:03:30 +0000 (14:03 +0100)
dbus_server_get_address() returns a copy. It isn't clear why.

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

test/loopback.c

index 5232a09..46e9758 100644 (file)
@@ -160,10 +160,12 @@ static void
 test_connect (Fixture *f,
     gconstpointer addr G_GNUC_UNUSED)
 {
+  char *address;
   g_assert (f->server_conn == NULL);
 
-  f->client_conn = dbus_connection_open_private (
-      dbus_server_get_address (f->server), &f->e);
+  address = dbus_server_get_address (f->server);
+  g_test_message ("listening at %s", address);
+  f->client_conn = dbus_connection_open_private (address, &f->e);
   assert_no_error (&f->e);
   g_assert (f->client_conn != NULL);
   test_connection_setup (f->ctx, f->client_conn);
@@ -173,6 +175,8 @@ test_connect (Fixture *f,
       test_progress ('.');
       test_main_context_iterate (f->ctx, TRUE);
     }
+
+  dbus_free (address);
 }
 
 static void
@@ -180,7 +184,7 @@ test_bad_guid (Fixture *f,
     gconstpointer addr G_GNUC_UNUSED)
 {
   DBusMessage *incoming;
-  gchar *address = g_strdup (dbus_server_get_address (f->server));
+  char *address = dbus_server_get_address (f->server);
   gchar *guid;
 
   g_test_bug ("39720");
@@ -232,7 +236,7 @@ test_bad_guid (Fixture *f,
 
   dbus_message_unref (incoming);
 
-  g_free (address);
+  dbus_free (address);
 }
 
 static void