summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-03-04 16:52:38 (GMT)
committerThomas Haller <thaller@redhat.com>2022-03-04 20:34:42 (GMT)
commit38b3be3ef2ba545111d346076955298a06d61cad (patch)
tree7f4e6ec7e1ef2f2e9fe5ecc9cc230ef12af07805 /tests
parentc2b94b93a8d9bee3fe3ad4ae6a5cdd52cee2968b (diff)
downloadlibnl-38b3be3ef2ba545111d346076955298a06d61cad.zip
libnl-38b3be3ef2ba545111d346076955298a06d61cad.tar.gz
libnl-38b3be3ef2ba545111d346076955298a06d61cad.tar.bz2
tests: cleanup tests and avoid leaks
It's important to have no leaks in tests. Otherwise, we cannot distinguish irrelevant leaks from actual bugs in valgrind. Do some cleanup.
Diffstat (limited to 'tests')
-rw-r--r--tests/check-ematch-tree-clone.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/tests/check-ematch-tree-clone.c b/tests/check-ematch-tree-clone.c
index 527b9cb..9f69646 100644
--- a/tests/check-ematch-tree-clone.c
+++ b/tests/check-ematch-tree-clone.c
@@ -1,13 +1,12 @@
-#include <netlink-private/types.h>
-#include <netlink/route/cls/ematch.h>
-
#include <linux/netlink.h>
-
#include <stdio.h>
#include <time.h>
-
#include <check.h>
+
+#include "netlink-private/types.h"
+#include "netlink/route/cls/ematch.h"
#include "util.h"
+#include "netlink-private/nl-auto.h"
#define MAX_DEPTH 6
#define MAX_CHILDREN 5
@@ -16,8 +15,6 @@ static int current_depth = 0;
static int id = 1;
static long long array_size = 0;
-static int *src_result = NULL, *dst_result = NULL;
-
static long long my_pow(long long x, long long y)
{
int ret = x;
@@ -107,8 +104,12 @@ static int compare(int *r1, int *r2, int len)
START_TEST(ematch_tree_clone)
{
- struct rtnl_ematch_tree *src = NULL, *dst = NULL;
- int i = 0, j = 0;
+ _nl_auto_rtnl_ematch_tree struct rtnl_ematch_tree *src = NULL;
+ _nl_auto_rtnl_ematch_tree struct rtnl_ematch_tree *dst = NULL;
+ _nl_auto_free int *src_result = NULL;
+ _nl_auto_free int *dst_result = NULL;
+ int i = 0;
+ int j = 0;
array_size = (MAX_DEPTH * my_pow(MAX_CHILDREN, MAX_DEPTH)) / 2;
src_result = calloc(4, array_size);
@@ -125,9 +126,6 @@ START_TEST(ematch_tree_clone)
ck_assert(dst);
ck_assert(i == j);
ck_assert(!compare(src_result, dst_result, i));
-
- free(src_result);
- free(dst_result);
}
END_TEST