From dff1090481bc64c9c38320ceffe3057ce0537e14 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 22 Feb 2025 16:20:04 +0000 Subject: [PATCH] tests: Remove various smaller memory "leaks" There are not critical because the test suite does not run for very long. Signed-off-by: Michael Tremer --- tests/libpakfire/archive.c | 4 +++- tests/libpakfire/jail.c | 9 +++++++-- tests/libpakfire/log_buffer.c | 2 ++ tests/libpakfire/makefile.c | 2 ++ tests/libpakfire/package.c | 2 ++ tests/libpakfire/repo.c | 2 ++ tests/libpakfire/util.c | 2 ++ 7 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/libpakfire/archive.c b/tests/libpakfire/archive.c index dc8809b8b..ee51f1b96 100644 --- a/tests/libpakfire/archive.c +++ b/tests/libpakfire/archive.c @@ -154,8 +154,10 @@ FAIL: pakfire_archive_unref(archive); if (f) fclose(f); - if (path) + if (path) { unlink(path); + free(path); + } return r; } diff --git a/tests/libpakfire/jail.c b/tests/libpakfire/jail.c index 05513ac5f..2e29670c8 100644 --- a/tests/libpakfire/jail.c +++ b/tests/libpakfire/jail.c @@ -106,6 +106,7 @@ FAIL: static int test_exec(const struct test* t) { struct pakfire_jail* jail = NULL; + int r = EXIT_FAILURE; char* output = NULL; size_t length = 0; @@ -122,10 +123,14 @@ static int test_exec(const struct test* t) { // Destroy it ASSERT_NULL(pakfire_jail_unref(jail)); - return EXIT_SUCCESS; + // Success + r = EXIT_SUCCESS; FAIL: - return EXIT_FAILURE; + if (output) + free(output); + + return r; } static int test_launch_into_cgroup(const struct test* t) { diff --git a/tests/libpakfire/log_buffer.c b/tests/libpakfire/log_buffer.c index 26f2e010b..a16a0a900 100644 --- a/tests/libpakfire/log_buffer.c +++ b/tests/libpakfire/log_buffer.c @@ -130,10 +130,12 @@ static int test_full(const struct test* t) { // On dequeue we should now miss Line 1, but get Line 2 instead ASSERT_SUCCESS(pakfire_log_buffer_dequeue(buffer, ×tamp, &priority, &line, &length)); ASSERT_STRING_EQUALS(line, "Line 2"); + free(line); // On the next iteration, we should get Line 3 ASSERT_SUCCESS(pakfire_log_buffer_dequeue(buffer, ×tamp, &priority, &line, &length)); ASSERT_STRING_EQUALS(line, "Line 3"); + free(line); // On the next iteration, the buffer should be empty ASSERT_SUCCESS(pakfire_log_buffer_dequeue(buffer, ×tamp, &priority, &line, &length)); diff --git a/tests/libpakfire/makefile.c b/tests/libpakfire/makefile.c index 8a854d422..04bcf91ff 100644 --- a/tests/libpakfire/makefile.c +++ b/tests/libpakfire/makefile.c @@ -256,6 +256,8 @@ FAIL: pakfire_filelist_unref(filelist); if (package) pakfire_package_unref(package); + if (tmp) + free(tmp); return r; } diff --git a/tests/libpakfire/package.c b/tests/libpakfire/package.c index 0832fcea8..a800e47d0 100644 --- a/tests/libpakfire/package.c +++ b/tests/libpakfire/package.c @@ -241,6 +241,8 @@ static int test_deps(const struct test* t) { r = EXIT_SUCCESS; FAIL: + if (deps) + pakfire_strings_free(deps); if (pkg) pakfire_package_unref(pkg); diff --git a/tests/libpakfire/repo.c b/tests/libpakfire/repo.c index 5e0d88113..d1ae95a36 100644 --- a/tests/libpakfire/repo.c +++ b/tests/libpakfire/repo.c @@ -99,6 +99,8 @@ static int test_compose(const struct test* t) { FAIL: if (repo) pakfire_repo_unref(repo); + if (path) + free(path); return r; } diff --git a/tests/libpakfire/util.c b/tests/libpakfire/util.c index 8189392d6..e4c4e21ac 100644 --- a/tests/libpakfire/util.c +++ b/tests/libpakfire/util.c @@ -84,6 +84,8 @@ static int test_base64(const struct test* t) { FAIL: if (base64) free(base64); + if (output) + free(output); return r; } -- 2.39.5