]> git.ipfire.org Git - pakfire.git/commitdiff
package: Fix cleanup code
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 28 Jun 2025 08:46:17 +0000 (08:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 28 Jun 2025 08:46:17 +0000 (08:46 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/package.c

index fa7746142b3e3e9401c63430fa66438afa4fe7a6..292b926cf25cca148cba930da93ef08d617d67a0 100644 (file)
@@ -1918,7 +1918,11 @@ char* pakfire_package_dump(pakfire_package* pkg, int flags) {
        enum pakfire_hash_type hash = PAKFIRE_HASH_UNDEFINED;
        const unsigned char* checksum = NULL;
        size_t checksum_length = 0;
+       char** build_arches = NULL;
+       pakfire_repo* repo = NULL;
+       char** groups = NULL;
        char* result = NULL;
+       char** deps = NULL;
        char** s = NULL;
        int r;
 
@@ -1974,7 +1978,7 @@ char* pakfire_package_dump(pakfire_package* pkg, int flags) {
        }
 
        // Repository
-       pakfire_repo* repo = pakfire_package_get_repo(pkg);
+       repo = pakfire_package_get_repo(pkg);
        if (repo) {
                if (!pakfire_repo_name_equals(repo, PAKFIRE_REPO_DUMMY)) {
                        const char* repo_name = pakfire_repo_get_name(repo);
@@ -1983,8 +1987,6 @@ char* pakfire_package_dump(pakfire_package* pkg, int flags) {
                        if (r < 0)
                                goto ERROR;
                }
-
-               pakfire_repo_unref(repo);
        }
 
        // Summary
@@ -2004,14 +2006,11 @@ char* pakfire_package_dump(pakfire_package* pkg, int flags) {
        }
 
        // Groups
-       char** groups = pakfire_package_get_strings(pkg, PAKFIRE_PKG_GROUPS);
+       groups = pakfire_package_get_strings(pkg, PAKFIRE_PKG_GROUPS);
        if (groups) {
                r = pakfire_package_dump_add_lines(&s, _("Groups"), groups);
                if (r < 0)
                        goto ERROR;
-
-               // XXX Needs free on error
-               pakfire_strings_free(groups);
        }
 
        // URL
@@ -2080,14 +2079,11 @@ char* pakfire_package_dump(pakfire_package* pkg, int flags) {
                }
 
                // Build Arches
-               char** build_arches = pakfire_package_get_strings(pkg, PAKFIRE_PKG_BUILD_ARCHES);
+               build_arches = pakfire_package_get_strings(pkg, PAKFIRE_PKG_BUILD_ARCHES);
                if (build_arches) {
                        r = pakfire_package_dump_add_lines(&s, _("Build Arch"), build_arches);
                        if (r < 0)
                                goto ERROR;
-
-                       // XXX needs free on error
-                       pakfire_strings_free(build_arches);
                }
 
                // Digest
@@ -2144,7 +2140,7 @@ char* pakfire_package_dump(pakfire_package* pkg, int flags) {
 
                // Dependencies
                for (const struct pakfire_dep* dep = pakfire_deps; dep->key; dep++) {
-                       char** deps = pakfire_package_get_deps(pkg, dep->key);
+                       deps = pakfire_package_get_deps(pkg, dep->key);
                        if (deps) {
                                size_t count = 0;
 
@@ -2202,8 +2198,8 @@ char* pakfire_package_dump(pakfire_package* pkg, int flags) {
                                if (r < 0)
                                        goto ERROR;
 
-                               // XXX needs free on error
                                pakfire_strings_free(deps);
+                               deps = NULL;
                        }
                }
        }
@@ -2236,6 +2232,14 @@ char* pakfire_package_dump(pakfire_package* pkg, int flags) {
        result = pakfire_string_join((const char**)s, "");
 
 ERROR:
+       if (build_arches)
+               pakfire_strings_free(build_arches);
+       if (groups)
+               pakfire_strings_free(groups);
+       if (deps)
+               pakfire_strings_free(deps);
+       if (repo)
+               pakfire_repo_unref(repo);
        if (s)
                pakfire_strings_free(s);