]> git.ipfire.org Git - pakfire.git/commitdiff
tests: Ensure that values are initialized before free
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 23 Oct 2024 12:18:52 +0000 (12:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 27 Oct 2024 11:37:24 +0000 (11:37 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/config.c
tests/libpakfire/db.c

index baa6e572328edd8b668d432c2940036a44ec2461..04bd83fa2e485669424f5bbec9885bc34d2de72a 100644 (file)
@@ -147,7 +147,8 @@ static int test_parse(const struct test* t) {
 FAIL:
        if (f)
                fclose(f);
-       pakfire_config_unref(config);
+       if (config)
+               pakfire_config_unref(config);
 
        return r;
 }
@@ -182,7 +183,8 @@ static int test_parse_multiline(const struct test* t) {
 FAIL:
        if (f)
                fclose(f);
-       pakfire_config_unref(config);
+       if (config)
+               pakfire_config_unref(config);
 
        return r;
 }
index bc2cf819a920f2dd33d694d9115007c92c821a8f..795790b89ea27a455c4f131d658b84e0e28f3aa2 100644 (file)
@@ -78,6 +78,7 @@ FAIL:
 }
 
 static int test_add_package(const struct test* t) {
+       struct pakfire_package* package = NULL;
        struct pakfire_db* db = NULL;
        struct pakfire_repo* repo = NULL;
        struct pakfire_archive* archive = NULL;
@@ -97,8 +98,6 @@ static int test_add_package(const struct test* t) {
        ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, path));
        ASSERT(archive);
 
-       struct pakfire_package* package = NULL;
-
        // Get package
        ASSERT_SUCCESS(pakfire_archive_make_package(archive, repo, &package));
        ASSERT(package);