From: Michael Tremer Date: Mon, 15 Jan 2018 23:40:23 +0000 (+0100) Subject: libpakfire: Make pakfire_unref the same style as others X-Git-Tag: 0.9.28~1285^2~1177 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8c916a4d24498fa2a22d82fc8901d3af5f932364;p=pakfire.git libpakfire: Make pakfire_unref the same style as others Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index b892674a3..0e8a8b94f 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -28,7 +28,7 @@ int pakfire_init(); Pakfire pakfire_create(const char* path, const char* arch); Pakfire pakfire_ref(Pakfire pakfire); -void pakfire_unref(Pakfire pakfire); +Pakfire pakfire_unref(Pakfire pakfire); const char* pakfire_get_path(Pakfire pakfire); const char* pakfire_get_arch(Pakfire pakfire); diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index d6a82589d..fe19d2e15 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -75,17 +75,23 @@ PAKFIRE_EXPORT Pakfire pakfire_ref(Pakfire pakfire) { return pakfire; } -PAKFIRE_EXPORT void pakfire_unref(Pakfire pakfire) { +PAKFIRE_EXPORT Pakfire pakfire_unref(Pakfire pakfire) { + if (!pakfire) + return NULL; + if (--pakfire->nrefs > 0) - return; + return pakfire; pakfire_pool_unref(pakfire->pool); pakfire_free(pakfire->path); pakfire_free(pakfire->arch); - DEBUG("Pakfire released at %p\n", pakfire); pakfire_free(pakfire); + + DEBUG("Pakfire released at %p\n", pakfire); + + return NULL; } PAKFIRE_EXPORT const char* pakfire_get_path(Pakfire pakfire) {