]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Remove various smaller memory "leaks"
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 22 Feb 2025 16:20:04 +0000 (16:20 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 22 Feb 2025 16:20:04 +0000 (16:20 +0000)
There are not critical because the test suite does not run for very
long.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/archive.c
tests/libpakfire/jail.c
tests/libpakfire/log_buffer.c
tests/libpakfire/makefile.c
tests/libpakfire/package.c
tests/libpakfire/repo.c
tests/libpakfire/util.c

index dc8809b8bf975b60acd531a165f53bb3f9af3fb7..ee51f1b964ad3b1d2421968b4c17a6d357821c33 100644 (file)
@@ -154,8 +154,10 @@ FAIL:
                pakfire_archive_unref(archive);
        if (f)
                fclose(f);
-       if (path)
+       if (path) {
                unlink(path);
+               free(path);
+       }
 
        return r;
 }
index 05513ac5f30c268b861c07685fa1432ff7a17192..2e29670c86f24ebddc08bf4e1fbecd306973eef1 100644 (file)
@@ -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) {
index 26f2e010b39c87432ec39f7ae422d46e24c3753b..a16a0a900464afce1feffb673aceb29ab3b258e3 100644 (file)
@@ -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, &timestamp, &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, &timestamp, &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, &timestamp, &priority, &line, &length));
index 8a854d422e6398973c38293bdb88dd87c98f0536..04bcf91ffbbca2649e2db5547f06dc625d7980c1 100644 (file)
@@ -256,6 +256,8 @@ FAIL:
                pakfire_filelist_unref(filelist);
        if (package)
                pakfire_package_unref(package);
+       if (tmp)
+               free(tmp);
 
        return r;
 }
index 0832fcea8aed85a2be197591a6f69afe648250c2..a800e47d02a76b2f3cd75a0e182f4199fdad6e7b 100644 (file)
@@ -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);
 
index 5e0d88113483c51ba016ce0f9076e2350e8a9cd1..d1ae95a36636f193c265974f5c13039839b4f35a 100644 (file)
@@ -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;
 }
index 8189392d665a76939504631857faae7743aee7cf..e4c4e21acb05cab91abe126fd58595649461d6ba 100644 (file)
@@ -84,6 +84,8 @@ static int test_base64(const struct test* t) {
 FAIL:
        if (base64)
                free(base64);
+       if (output)
+               free(output);
 
        return r;
 }