]> git.ipfire.org Git - pakfire.git/commitdiff
tests: string: Free string after the replace test
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 4 Oct 2023 15:34:54 +0000 (15:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 4 Oct 2023 15:34:54 +0000 (15:34 +0000)
Generally, we do not free stuff in the tests (because we don't care
about any leaks), but I wanted to see a clear valgrind result on this
one...

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/string.c

index 38e56479d6b74483f1ae3ad109651598c8e8110a..bcf8e1357b45de60707d3632114be33b09467d95 100644 (file)
@@ -148,15 +148,21 @@ FAIL:
 }
 
 static int test_string_replace(const struct test* t) {
-       const char* result = pakfire_string_replace(
+       int r = EXIT_FAILURE;
+
+       char* result = pakfire_string_replace(
                "ABCABCABCABC", "AB", "CC"
        );
        ASSERT_STRING_EQUALS(result, "CCCCCCCCCCCC");
 
-       return EXIT_SUCCESS;
+       // Success
+       r = EXIT_SUCCESS;
 
 FAIL:
-       return EXIT_FAILURE;
+       if (result)
+               free(result);
+
+       return r;
 }
 
 static int test_string_join(const struct test* t) {