From d5f343f3fbfaebb4a6c75776cf3abc2a671eb974 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 21 Jul 2023 18:15:45 +0000 Subject: [PATCH] dependencies: Create and destroy the pool for each version check The former solution obviously wasn't very thread-safe. Signed-off-by: Michael Tremer --- src/libpakfire/dependencies.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/libpakfire/dependencies.c b/src/libpakfire/dependencies.c index d457e7d3d..49f25da80 100644 --- a/src/libpakfire/dependencies.c +++ b/src/libpakfire/dependencies.c @@ -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) { -- 2.39.5