[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/8] curl: Remove unnecessary use of goto
From: |
Matthew Booth |
Subject: |
[Qemu-devel] [PATCH 2/8] curl: Remove unnecessary use of goto |
Date: |
Tue, 29 Apr 2014 16:03:26 +0100 |
This isn't any of the usually acceptable uses of goto.
Signed-off-by: Matthew Booth <address@hidden>
---
block/curl.c | 55 +++++++++++++++++++++++++++----------------------------
1 file changed, 27 insertions(+), 28 deletions(-)
diff --git a/block/curl.c b/block/curl.c
index 0404dbd..e97f449 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -343,39 +343,38 @@ static CURLState *curl_init_state(BDRVCURLState *s)
}
} while(!state);
- if (state->curl)
- goto has_curl;
-
- state->curl = curl_easy_init();
- if (!state->curl)
- return NULL;
- curl_easy_setopt(state->curl, CURLOPT_URL, s->url);
- curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, 5);
- curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION, (void *)curl_read_cb);
- curl_easy_setopt(state->curl, CURLOPT_WRITEDATA, (void *)state);
- curl_easy_setopt(state->curl, CURLOPT_PRIVATE, (void *)state);
- curl_easy_setopt(state->curl, CURLOPT_AUTOREFERER, 1);
- curl_easy_setopt(state->curl, CURLOPT_FOLLOWLOCATION, 1);
- curl_easy_setopt(state->curl, CURLOPT_NOSIGNAL, 1);
- curl_easy_setopt(state->curl, CURLOPT_ERRORBUFFER, state->errmsg);
- curl_easy_setopt(state->curl, CURLOPT_FAILONERROR, 1);
-
- /* Restrict supported protocols to avoid security issues in the more
- * obscure protocols. For example, do not allow POP3/SMTP/IMAP see
- * CVE-2013-0249.
- *
- * Restricting protocols is only supported from 7.19.4 upwards.
- */
+ if (!state->curl) {
+ state->curl = curl_easy_init();
+ if (!state->curl) {
+ return NULL;
+ }
+ curl_easy_setopt(state->curl, CURLOPT_URL, s->url);
+ curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, 5);
+ curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION,
+ (void *)curl_read_cb);
+ curl_easy_setopt(state->curl, CURLOPT_WRITEDATA, (void *)state);
+ curl_easy_setopt(state->curl, CURLOPT_PRIVATE, (void *)state);
+ curl_easy_setopt(state->curl, CURLOPT_AUTOREFERER, 1);
+ curl_easy_setopt(state->curl, CURLOPT_FOLLOWLOCATION, 1);
+ curl_easy_setopt(state->curl, CURLOPT_NOSIGNAL, 1);
+ curl_easy_setopt(state->curl, CURLOPT_ERRORBUFFER, state->errmsg);
+ curl_easy_setopt(state->curl, CURLOPT_FAILONERROR, 1);
+
+ /* Restrict supported protocols to avoid security issues in the more
+ * obscure protocols. For example, do not allow POP3/SMTP/IMAP see
+ * CVE-2013-0249.
+ *
+ * Restricting protocols is only supported from 7.19.4 upwards.
+ */
#if LIBCURL_VERSION_NUM >= 0x071304
- curl_easy_setopt(state->curl, CURLOPT_PROTOCOLS, PROTOCOLS);
- curl_easy_setopt(state->curl, CURLOPT_REDIR_PROTOCOLS, PROTOCOLS);
+ curl_easy_setopt(state->curl, CURLOPT_PROTOCOLS, PROTOCOLS);
+ curl_easy_setopt(state->curl, CURLOPT_REDIR_PROTOCOLS, PROTOCOLS);
#endif
#ifdef DEBUG_VERBOSE
- curl_easy_setopt(state->curl, CURLOPT_VERBOSE, 1);
+ curl_easy_setopt(state->curl, CURLOPT_VERBOSE, 1);
#endif
-
-has_curl:
+ }
state->s = s;
--
1.9.0
- [Qemu-devel] [PATCH 0/8] curl: Fix hang reading from slow connections, Matthew Booth, 2014/04/29
- [Qemu-devel] [PATCH 1/8] curl: Fix long line, Matthew Booth, 2014/04/29
- [Qemu-devel] [PATCH 2/8] curl: Remove unnecessary use of goto,
Matthew Booth <=
- [Qemu-devel] [PATCH 5/8] curl: Remove unnecessary explicit calls to internal event handler, Matthew Booth, 2014/04/29
- [Qemu-devel] [PATCH 4/8] curl: Remove erroneous sleep waiting for curl completion, Matthew Booth, 2014/04/29
- [Qemu-devel] [PATCH 7/8] curl: Ensure all informationals are checked for completion, Matthew Booth, 2014/04/29
- [Qemu-devel] [PATCH 3/8] curl: Fix return from curl_read_cb with invalid state, Matthew Booth, 2014/04/29
- [Qemu-devel] [PATCH 6/8] curl: Eliminate unnecessary use of curl_multi_socket_all, Matthew Booth, 2014/04/29
- [Qemu-devel] [PATCH 8/8] curl: Fix hang reading from slow connections, Matthew Booth, 2014/04/29
- Re: [Qemu-devel] [PATCH 0/8] curl: Fix hang reading from slow connections, Richard W.M. Jones, 2014/04/29
- Re: [Qemu-devel] [PATCH 0/8] curl: Fix hang reading from slow connections, Kevin Wolf, 2014/04/30