From: Michael Tremer Date: Fri, 31 Jan 2025 10:09:52 +0000 (+0000) Subject: repo: Instead of passing around flags, automatically free the repo X-Git-Tag: 0.9.30~222 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c757904fe8c1d0c36a359a9ca506995451506599;p=pakfire.git repo: Instead of passing around flags, automatically free the repo Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index ac021962..1c46805f 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -62,6 +62,9 @@ struct pakfire_repo_appdata { // Reference Counter int nrefs; + // SOLV Repo + Repo* repo; + // Description char description[MAX_DESCRIPTION]; @@ -798,20 +801,13 @@ static void pakfire_repo_free_appdata(struct pakfire_repo_appdata* appdata) { if (--appdata->nrefs > 0) return; + // If there are no further references, automatically destroy the entire repository + repo_free(appdata->repo, 0); + free(appdata); } -static void pakfire_repo_free(struct pakfire_repo* self, const int free_repo) { - // Optionally free appdata - if (free_repo) { - if (self->repo) { - if (self->repo->appdata) - pakfire_repo_free_appdata(self->repo->appdata); - - repo_free(self->repo, 0); - } - } - +static void pakfire_repo_free(struct pakfire_repo* self) { if (self->appdata) pakfire_repo_free_appdata(self->appdata); if (self->mirrorlist) @@ -826,18 +822,17 @@ static void pakfire_repo_free(struct pakfire_repo* self, const int free_repo) { } void pakfire_repo_free_all(struct pakfire* pakfire) { + Repo* repo = NULL; + int i; + + // Fetch the pool Pool* pool = pakfire_get_solv_pool(pakfire); if (!pool) return; - Repo* repo; - int i; - FOR_REPOS(i, repo) { if (repo->appdata) pakfire_repo_free_appdata(repo->appdata); - - repo_free(repo, 0); } } @@ -852,6 +847,9 @@ static int pakfire_repo_setup_appdata(struct pakfire_repo* self) { // Initialize the reference counter appdata->nrefs = 2; + // Reference the SOLV repository + appdata->repo = self->repo; + // Refresh Interval: Set to invalid appdata->refresh = -1; @@ -930,7 +928,9 @@ int pakfire_repo_create(struct pakfire_repo** repo, return 0; ERROR: - pakfire_repo_free(self, 1); + if (self->appdata) + pakfire_repo_free_appdata(self->appdata); + pakfire_repo_free(self); return r; } @@ -975,7 +975,7 @@ struct pakfire_repo* pakfire_repo_unref(struct pakfire_repo* repo) { if (--repo->nrefs > 0) return repo; - pakfire_repo_free(repo, 0); + pakfire_repo_free(repo); return NULL; }