{"thread":{"id":"37344","subject":"[PATCH] http.c: die if curl_*_init fails","startedAt":"2014-08-13T17:31:24Z","lastAt":"2014-08-17T07:35:53Z","messageCount":2,"participants":["Bernhard Reiter","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"247677","messageId":"53EBA0EC.9000007@raz.or.at","threadId":"37344","inReplyTo":null,"subject":"[PATCH] http.c: die if curl_*_init fails","fromName":"Bernhard Reiter","fromEmail":"ockham@raz.or.at","sentAt":"2014-08-13T17:31:24Z","receivedAt":"2014-08-13T17:31:24Z","isPatch":true,"sender":{"key":"ockham@raz.or.at","avatar":"https://avatars.githubusercontent.com/u/96308?v=4"},"body":"\nSigned-off-by: Bernhard Reiter <ockham@raz.or.at>\n---\n http.c | 6 +++++-\n 1 file changed, 5 insertions(+), 1 deletion(-)\n\n\n\n\ndiff --git a/http.c b/http.c\nindex c8cd50d..afe4fc5 100644\n--- a/http.c\n+++ b/http.c\n@@ -300,6 +300,9 @@ static CURL *get_curl_handle(void)\n {\n \tCURL *result = curl_easy_init();\n \n+\tif (!result)\n+\t\tdie(\"curl_easy_init failed\");\n+\n \tif (!curl_ssl_verify) {\n \t\tcurl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, 0);\n \t\tcurl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 0);\n@@ -399,7 +402,8 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)\n \tgit_config(urlmatch_config_entry, &config);\n \tfree(normalized_url);\n \n-\tcurl_global_init(CURL_GLOBAL_ALL);\n+\tif (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK)\n+\t\tdie(\"curl_global_init failed\");\n \n \thttp_proactive_auth = proactive_auth;\n \n\n"},{"id":"247806","messageId":"20140817073553.GG23808@peff.net","threadId":"37344","inReplyTo":"53EBA0EC.9000007@raz.or.at","subject":"Re: [PATCH] http.c: die if curl_*_init fails","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-08-17T07:35:53Z","receivedAt":"2014-08-17T07:35:53Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Aug 13, 2014 at 07:31:24PM +0200, Bernhard Reiter wrote:\n\n> diff --git a/http.c b/http.c\n> index c8cd50d..afe4fc5 100644\n> --- a/http.c\n> +++ b/http.c\n> @@ -300,6 +300,9 @@ static CURL *get_curl_handle(void)\n>  {\n>  \tCURL *result = curl_easy_init();\n>  \n> +\tif (!result)\n> +\t\tdie(\"curl_easy_init failed\");\n> +\n>  \tif (!curl_ssl_verify) {\n>  \t\tcurl_easy_setopt(result, CURLOPT_SSL_VERIFYPEER, 0);\n>  \t\tcurl_easy_setopt(result, CURLOPT_SSL_VERIFYHOST, 0);\n> @@ -399,7 +402,8 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)\n>  \tgit_config(urlmatch_config_entry, &config);\n>  \tfree(normalized_url);\n>  \n> -\tcurl_global_init(CURL_GLOBAL_ALL);\n> +\tif (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK)\n> +\t\tdie(\"curl_global_init failed\");\n>  \n>  \thttp_proactive_auth = proactive_auth;\n\nLooks good. I wondered if curl_multi_init needed the same, but it seems\nwe already check its return. Its style does not match the rest of the\ncode, though. Maybe we should squash in (or apply on top):\n\n-- >8 --\nSubject: http: style fixes for curl_multi_init error check\n\nUnless there is a good reason, we should use die() rather than\nfprintf/exit. We can also shorten the message to match other curl init\nfailures (and match our usual lowercase no-full-stop style).\n\n---\ndiff --git a/http.c b/http.c\nindex c8cd50d..4e651a2 100644\n--- a/http.c\n+++ b/http.c\n@@ -417,10 +417,8 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)\n \t}\n \n \tcurlm = curl_multi_init();\n-\tif (curlm == NULL) {\n-\t\tfprintf(stderr, \"Error creating curl multi handle.\\n\");\n-\t\texit(1);\n-\t}\n+\tif (!curlm)\n+\t\tdie(\"curl_multi_init failed\");\n #endif\n \n \tif (getenv(\"GIT_SSL_NO_VERIFY\"))\n"}]}