qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 2/6] curl: Keep *socket until the end of curl_sock_c


From: Max Reitz
Subject: [Qemu-devel] [PATCH 2/6] curl: Keep *socket until the end of curl_sock_cb()
Date: Tue, 27 Aug 2019 18:34:35 +0200

This does not really change anything, but it makes the code a bit easier
to follow once we use @socket as the opaque pointer for
aio_set_fd_handler().

(Also, this change stops us from creating new CURLSocket objects when
the cURL library just wants to stop listening on an existing socket that
we do not recognize.  With a well-behaving cURL, that should never
happen anyway.)

Cc: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
 block/curl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/block/curl.c b/block/curl.c
index 92dc2f630e..8a45b371cc 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -174,18 +174,16 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int 
action,
         if (socket->fd == fd) {
             if (action == CURL_POLL_REMOVE) {
                 QLIST_REMOVE(socket, next);
-                g_free(socket);
             }
             break;
         }
     }
-    if (!socket) {
+    if (action != CURL_POLL_REMOVE && !socket) {
         socket = g_new0(CURLSocket, 1);
         socket->fd = fd;
         socket->state = state;
         QLIST_INSERT_HEAD(&state->sockets, socket, next);
     }
-    socket = NULL;
 
     trace_curl_sock_cb(action, (int)fd);
     switch (action) {
@@ -207,6 +205,9 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int 
action,
             break;
     }
 
+    if (action == CURL_POLL_REMOVE) {
+        g_free(socket);
+    }
     return 0;
 }
 
-- 
2.21.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]