]> git.ipfire.org Git - pakfire.git/commitdiff
dependencies: Create and destroy the pool for each version check
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Jul 2023 18:15:45 +0000 (18:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Jul 2023 18:15:45 +0000 (18:15 +0000)
The former solution obviously wasn't very thread-safe.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/dependencies.c

index d457e7d3d258c0a4b26bd73cbbf19eaebe986360..49f25da80c3bf3e8f4995455798934610645a549 100644 (file)
@@ -61,25 +61,28 @@ static const struct pakfire_rich_operation {
        { NULL, 0 },
 };
 
-static Pool* __pool = NULL;
-
 /*
        This function can compare package versions without a Pakfire instance initialized.
 */
 PAKFIRE_EXPORT int pakfire_static_version_compare(const char* evr1, const char* evr2) {
-       // Initialize the pool (unless already done)
-       if (!__pool) {
-               __pool = pool_create();
+       Pool* pool = NULL;
+       int r;
 
-               if (!__pool)
-                       return 0;
+       // Initialize the pool
+       pool = pool_create();
+       if (!pool)
+               return 0;
 
-               // Set to RPM mode
-               pool_setdisttype(__pool, DISTTYPE_RPM);
-       }
+       // Set to RPM mode
+       pool_setdisttype(pool, DISTTYPE_RPM);
 
        // Perform comparison
-       return pool_evrcmp_str(__pool, evr1, evr2, EVRCMP_COMPARE);
+       r = pool_evrcmp_str(pool, evr1, evr2, EVRCMP_COMPARE);
+
+       // Free the pool
+       pool_free(pool);
+
+       return r;
 }
 
 const char* pakfire_dep2str(struct pakfire* pakfire, Id id) {