]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: test-http-payload - Implement reference counting for client request.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Wed, 4 Apr 2018 01:02:24 +0000 (03:02 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 1 Dec 2020 16:38:47 +0000 (18:38 +0200)
src/lib-http/test-http-payload.c

index 06c91bea004dddf020e4815c7a0594ee0f022c38..d7278cd58ca79d8923bd90e2c9bc0354aa2d3d46 100644 (file)
@@ -876,6 +876,8 @@ static void test_server_deinit(void)
  */
 
 struct test_client_request {
+       int refcount;
+
        struct test_client_request *prev, *next;
        struct http_client_request *hreq;
 
@@ -895,13 +897,27 @@ static struct test_client_request *test_client_request_new(void)
        struct test_client_request *tcreq;
 
        tcreq = i_new(struct test_client_request, 1);
+       tcreq->refcount = 1;
        DLLIST_PREPEND(&client_requests, tcreq);
 
        return tcreq;
 }
 
-static void test_client_request_destroy(struct test_client_request *tcreq)
+static void test_client_request_ref(struct test_client_request *tcreq)
 {
+       tcreq->refcount++;
+}
+
+static void test_client_request_unref(struct test_client_request **_tcreq)
+{
+       struct test_client_request *tcreq = *_tcreq;
+
+       *_tcreq = NULL;
+
+       i_assert(tcreq->refcount > 0);
+       if (--tcreq->refcount > 0)
+               return;
+
        io_remove(&tcreq->io);
        i_stream_unref(&tcreq->payload);
        i_stream_unref(&tcreq->file_in);
@@ -910,6 +926,11 @@ static void test_client_request_destroy(struct test_client_request *tcreq)
        i_free(tcreq);
 }
 
+static void test_client_request_destroy(struct test_client_request *tcreq)
+{
+       test_client_request_unref(&tcreq);
+}
+
 static void test_client_switch_ioloop(void)
 {
        struct test_client_request *tcreq;