[glib/wip/pwithnall/network-address-test-fixes: 2/4] tests: Fix memory leaks in network-address test
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/pwithnall/network-address-test-fixes: 2/4] tests: Fix memory leaks in network-address test
- Date: Tue, 22 Feb 2022 11:23:32 +0000 (UTC)
commit d58f1900f183fe7d88c6e56691c56b5f4569c66a
Author: Philip Withnall <pwithnall endlessos org>
Date: Tue Feb 22 10:05:18 2022 +0000
tests: Fix memory leaks in network-address test
The test results weren’t being freed.
This makes the `network-address` test clean under memcheck for me.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
gio/tests/network-address.c | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/gio/tests/network-address.c b/gio/tests/network-address.c
index 946a8f25f..828d33c1b 100644
--- a/gio/tests/network-address.c
+++ b/gio/tests/network-address.c
@@ -768,16 +768,22 @@ sort_socket_addresses (gconstpointer a, gconstpointer b)
static void
assert_list_matches_expected (GList *result, GList *expected)
{
+ GList *result_copy = NULL;
+
g_assert_cmpint (g_list_length (result), ==, g_list_length (expected));
- /* Sort by ipv4 first which matches the expected list */
- result = g_list_sort (result, sort_socket_addresses);
+ /* Sort by ipv4 first which matches the expected list. Do this on a copy of
+ * @result to avoid modifying the original. */
+ result_copy = g_list_copy (result);
+ result = result_copy = g_list_sort (result_copy, sort_socket_addresses);
for (; result != NULL; result = result->next, expected = expected->next)
{
GInetAddress *address = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (result->data));
g_assert_true (g_inet_address_equal (address, expected->data));
}
+
+ g_list_free (result_copy);
}
typedef struct {
@@ -855,6 +861,8 @@ test_happy_eyeballs_basic (HappyEyeballsFixture *fixture,
g_main_loop_run (fixture->loop);
assert_list_matches_expected (data.addrs, fixture->input_all_results);
+
+ g_list_free_full (data.addrs, (GDestroyNotify) g_object_unref);
}
static void
@@ -879,6 +887,7 @@ test_happy_eyeballs_parallel (HappyEyeballsFixture *fixture,
/* Run again to ensure the cache from the previous one is correct */
+ g_list_free_full (data.addrs, (GDestroyNotify) g_object_unref);
data.addrs = NULL;
g_object_unref (enumerator2);
@@ -887,7 +896,9 @@ test_happy_eyeballs_parallel (HappyEyeballsFixture *fixture,
g_main_loop_run (fixture->loop);
assert_list_matches_expected (data.addrs, fixture->input_all_results);
+
g_object_unref (enumerator2);
+ g_list_free_full (data.addrs, (GDestroyNotify) g_object_unref);
}
static void
@@ -905,6 +916,8 @@ test_happy_eyeballs_slow_ipv4 (HappyEyeballsFixture *fixture,
g_main_loop_run (fixture->loop);
assert_list_matches_expected (data.addrs, fixture->input_all_results);
+
+ g_list_free_full (data.addrs, (GDestroyNotify) g_object_unref);
}
static void
@@ -922,6 +935,8 @@ test_happy_eyeballs_slow_ipv6 (HappyEyeballsFixture *fixture,
g_main_loop_run (fixture->loop);
assert_list_matches_expected (data.addrs, fixture->input_all_results);
+
+ g_list_free_full (data.addrs, (GDestroyNotify) g_object_unref);
}
static void
@@ -939,6 +954,8 @@ test_happy_eyeballs_very_slow_ipv6 (HappyEyeballsFixture *fixture,
g_main_loop_run (fixture->loop);
assert_list_matches_expected (data.addrs, fixture->input_all_results);
+
+ g_list_free_full (data.addrs, (GDestroyNotify) g_object_unref);
}
static void
@@ -958,6 +975,8 @@ test_happy_eyeballs_slow_connection_and_ipv4 (HappyEyeballsFixture *fixture,
g_main_loop_run (fixture->loop);
assert_list_matches_expected (data.addrs, fixture->input_all_results);
+
+ g_list_free_full (data.addrs, (GDestroyNotify) g_object_unref);
}
static void
@@ -979,6 +998,7 @@ test_happy_eyeballs_ipv6_error_ipv4_first (HappyEyeballsFixture *fixture,
assert_list_matches_expected (data.addrs, fixture->input_ipv4_results);
+ g_list_free_full (data.addrs, (GDestroyNotify) g_object_unref);
g_error_free (ipv6_error);
}
@@ -1001,6 +1021,7 @@ test_happy_eyeballs_ipv6_error_ipv6_first (HappyEyeballsFixture *fixture,
assert_list_matches_expected (data.addrs, fixture->input_ipv4_results);
+ g_list_free_full (data.addrs, (GDestroyNotify) g_object_unref);
g_error_free (ipv6_error);
}
@@ -1026,6 +1047,7 @@ test_happy_eyeballs_ipv6_error_ipv4_very_slow (HappyEyeballsFixture *fixture,
assert_list_matches_expected (data.addrs, fixture->input_ipv4_results);
+ g_list_free_full (data.addrs, (GDestroyNotify) g_object_unref);
g_error_free (ipv6_error);
}
@@ -1048,6 +1070,7 @@ test_happy_eyeballs_ipv4_error_ipv4_first (HappyEyeballsFixture *fixture,
assert_list_matches_expected (data.addrs, fixture->input_ipv6_results);
+ g_list_free_full (data.addrs, (GDestroyNotify) g_object_unref);
g_error_free (ipv4_error);
}
@@ -1070,6 +1093,7 @@ test_happy_eyeballs_ipv4_error_ipv6_first (HappyEyeballsFixture *fixture,
assert_list_matches_expected (data.addrs, fixture->input_ipv6_results);
+ g_list_free_full (data.addrs, (GDestroyNotify) g_object_unref);
g_error_free (ipv4_error);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]