[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
- [Qemu-devel] [PATCH 0/6] block/curl: Fix hang and potential crash, Max Reitz, 2019/08/27
- [Qemu-devel] [PATCH 1/6] curl: Keep pointer to the CURLState in CURLSocket, Max Reitz, 2019/08/27
- [Qemu-devel] [PATCH 2/6] curl: Keep *socket until the end of curl_sock_cb(),
Max Reitz <=
- [Qemu-devel] [PATCH 3/6] curl: Pass CURLSocket to curl_multi_{do, read}(), Max Reitz, 2019/08/27
- [Qemu-devel] [PATCH 4/6] curl: Report only ready sockets, Max Reitz, 2019/08/27
- [Qemu-devel] [PATCH 5/6] curl: Handle success in multi_check_completion, Max Reitz, 2019/08/27
- [Qemu-devel] [PATCH 6/6] curl: Check curl_multi_add_handle()'s return code, Max Reitz, 2019/08/27