From: Michael Tremer Date: Thu, 17 Oct 2024 15:28:40 +0000 (+0000) Subject: pakfire: Tidy up the code to create a new pakfire instance slightly X-Git-Tag: 0.9.30~1036 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3200db24e16ad4d12defd697eae7ae71623c9408;p=pakfire.git pakfire: Tidy up the code to create a new pakfire instance slightly Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 8223d77a0..9f5e338b6 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -765,30 +765,32 @@ ERROR: PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* ctx, const char* path, const char* arch, FILE* conf, int flags) { + struct pakfire* p = NULL; char tempdir[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-root-XXXXXX"; char private_dir[PATH_MAX]; int r = 1; - // Reset pakfire pointer - *pakfire = NULL; - // Default to the native architecture if (!arch) arch = pakfire_arch_native(); - struct pakfire* p = calloc(1, sizeof(*p)); + // Allocate a new object + p = calloc(1, sizeof(*p)); if (!p) return -errno; // Reference the context p->ctx = pakfire_ctx_ref(ctx); + // Initialize the reference counter p->nrefs = 1; + + // Store the flags p->flags = flags; // Store the nominal architecture r = pakfire_string_set(p->arches.nominal, arch); - if (r) + if (r < 0) goto ERROR; // Determine the effective architecture @@ -801,7 +803,7 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* // Setup user/group r = pakfire_setup_user(p); - if (r) + if (r < 0) goto ERROR; // Initialise configuration @@ -870,7 +872,9 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* } // Set path - pakfire_string_set(p->path, path); + r = pakfire_string_set(p->path, path); + if (r < 0) + goto ERROR; // Read /etc/os-release r = pakfire_read_os_release(p); @@ -924,20 +928,22 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* // Populate pool r = pakfire_populate_pool(p); - if (r) + if (r < 0) goto ERROR; // Create repositories r = pakfire_repo_import(p, p->config); - if (r) + if (r < 0) goto ERROR; - *pakfire = p; + // Return the pointer + *pakfire = pakfire_ref(p); return 0; ERROR: - pakfire_free(p); + if (p) + pakfire_unref(p); return r; } @@ -953,7 +959,6 @@ PAKFIRE_EXPORT struct pakfire* pakfire_unref(struct pakfire* pakfire) { return pakfire; pakfire_free(pakfire); - return NULL; }