]> git.ipfire.org Git - pakfire.git/commitdiff
client: Hold a reference to the event loop
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 24 Jun 2025 15:46:03 +0000 (15:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 24 Jun 2025 15:46:03 +0000 (15:46 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/client.c

index fa65af707da5d1ad72a05f04e97eeb144e3507e6..77f4ccf0c0f32b831fce4cb4f5be9fc146437910 100644 (file)
@@ -24,6 +24,8 @@
 
 #include <json.h>
 
+#include <systemd/sd-event.h>
+
 #include <pakfire/client.h>
 #include <pakfire/config.h>
 #include <pakfire/ctx.h>
@@ -41,6 +43,9 @@ struct pakfire_client {
        struct pakfire_ctx* ctx;
        int nrefs;
 
+       // Event Loop
+       sd_event* loop;
+
        // HTTP Client
        struct pakfire_httpclient* httpclient;
 
@@ -251,6 +256,10 @@ static int pakfire_client_xfer_auth(struct pakfire_client* self, struct pakfire_
 }
 
 static void pakfire_client_free(struct pakfire_client* self) {
+       // Event Loop
+       if (self->loop)
+               sd_event_unref(self->loop);
+
        if (self->httpclient)
                pakfire_httpclient_unref(self->httpclient);
        if (self->ctx)
@@ -275,8 +284,11 @@ int pakfire_client_create(struct pakfire_client** client,
        // Initialize the reference counter
        self->nrefs = 1;
 
+       // Store a reference to the event loop
+       self->loop = sd_event_ref(loop);
+
        // Create a new HTTP client
-       r = pakfire_httpclient_create(&self->httpclient, self->ctx, loop);
+       r = pakfire_httpclient_create(&self->httpclient, self->ctx, self->loop);
        if (r < 0)
                goto ERROR;