From: Michael Tremer Date: Thu, 30 Jan 2025 22:47:25 +0000 (+0000) Subject: repo: Check pointers before trying to free them X-Git-Tag: 0.9.30~231 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4a4c8dc6f3d448fa8e10a8d7c30ecf7caeece5f0;p=pakfire.git repo: Check pointers before trying to free them This is again for the static analyzer Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index ee78fcf8..e1d87755 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -790,28 +790,31 @@ static int pakfire_repo_refresh_metadata(struct pakfire_repo* repo, const int fo return pakfire_repo_read_metadata(repo, path); } -static void free_repo_appdata(struct pakfire_repo_appdata* appdata) { +static void pakfire_repo_free_appdata(struct pakfire_repo_appdata* appdata) { if (appdata) free(appdata); } -static void pakfire_repo_free(struct pakfire_repo* repo, const int free_repo) { +static void pakfire_repo_free(struct pakfire_repo* self, const int free_repo) { + // Optionally free appdata if (free_repo) { - free_repo_appdata(repo->repo->appdata); - repo_free(repo->repo, 0); - } + if (self->repo) { + if (self->repo->appdata) + pakfire_repo_free_appdata(self->repo->appdata); - // Free the key - if (repo->key) - pakfire_key_unref(repo->key); + repo_free(self->repo, 0); + } + } - if (repo->mirrorlist) - pakfire_mirrorlist_unref(repo->mirrorlist); - if (repo->pakfire) - pakfire_unref(repo->pakfire); - if (repo->ctx) - pakfire_ctx_unref(repo->ctx); - free(repo); + if (self->mirrorlist) + pakfire_mirrorlist_unref(self->mirrorlist); + if (self->pakfire) + pakfire_unref(self->pakfire); + if (self->key) + pakfire_key_unref(self->key); + if (self->ctx) + pakfire_ctx_unref(self->ctx); + free(self); } void pakfire_repo_free_all(struct pakfire* pakfire) { @@ -823,7 +826,9 @@ void pakfire_repo_free_all(struct pakfire* pakfire) { int i; FOR_REPOS(i, repo) { - free_repo_appdata(repo->appdata); + if (repo->appdata) + pakfire_repo_free_appdata(repo->appdata); + repo_free(repo, 0); } }