From: Michael Tremer Date: Sat, 28 Jun 2025 08:46:17 +0000 (+0000) Subject: package: Fix cleanup code X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=24d2d14ab0b7f52d6acd40bcc96d88da2d191b1e;p=pakfire.git package: Fix cleanup code Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/package.c b/src/pakfire/package.c index fa774614..292b926c 100644 --- a/src/pakfire/package.c +++ b/src/pakfire/package.c @@ -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);