]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire_free: Avoid multiple calls
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 5 Oct 2021 11:59:20 +0000 (11:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 5 Oct 2021 11:59:20 +0000 (11:59 +0000)
If we want to access any objects that use reference counting, we will
increment and then decrement the reference counter of struct pakfire.
This will cause that pakfire_free() will be called multiple times which
will go wrong.

This change blocks that that will happen.

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

index 8bde301e118a508972480141e47ba0360ec3c03e..56606ed4da652f932a5559107491545b9f400336 100644 (file)
@@ -110,6 +110,7 @@ struct pakfire {
        int destroy_on_free:1;
        int mount_tmpfs:1;
        int pool_ready:1;
+       int in_free:1;
 };
 
 /*
@@ -513,6 +514,10 @@ static int pakfire_mount_interpreter(struct pakfire* pakfire) {
 }
 
 static void pakfire_free(struct pakfire* pakfire) {
+       // Avoid recursive free
+       if (pakfire->in_free++)
+               return;
+
        // Release GPGME context
        if (pakfire->gpgctx)
                pakfire_keystore_destroy(pakfire, &pakfire->gpgctx);