[PATCH] Work around curl-gnutls not liking to be reinitialized

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <git@...>, <gitster@...>
Date: Friday, February 8, 2008 - 4:08 pm

Either recent curl or gnutls doesn't like initializing again after cleaning
up, and this is happening in some cases such as git fetch.

We work around this by removing the http_cleanup call from get_refs_via_curl,
and allowing http_init to be called several times without initializing http.c
global variables again and leaking old values.

The remaining calls to http_cleanup are either last (http-push.c), or almost
never called (walker.c; the function it lies in is only called from
transport-disconnect, which is called last, and only in builtin-push.c).
These leaks shall be addressed in the http code refactoring.

Signed-off-by: Mike Hommey <mh@glandium.org>
---

 > So, it looks like either gnutls has a problem reinitializing its ASN1
 > parser or curl is doing something wrong with gnutls when initializing a
 > new request.

 In the end, it was a bit of git's fault, but either curl or gnutls is the
 actual culprit. I've not looked into either code to find out who's
 responsible, but a very simplified testcase is as follows:

	#include <curl/curl.h>
	#include <curl/easy.h>

	int main(void) {
	        CURL *easy = curl_easy_init();
	        curl_easy_setopt(easy, CURLOPT_VERBOSE, 1);
	        curl_easy_setopt(easy, CURLOPT_URL, "https://www.verisign.com/");
	        curl_easy_perform(easy);
	        curl_global_cleanup();
	        easy = curl_easy_init();
	        curl_easy_setopt(easy, CURLOPT_VERBOSE, 1);
	        curl_easy_setopt(easy, CURLOPT_URL, "https://www.verisign.com/");
	        curl_easy_perform(easy);
	}

	(build with gcc -o test test.c -lcurl)
	(note curl_easy_init does curl_global_init behind the curtains, even the
	second time. You can convince yourself by adding
	curl_global_init(CURL_GLOBAL_ALL);)

 http.c      |    5 +++++
 transport.c |    2 --
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/http.c b/http.c
index d2c11ae..a3aa9e9 100644
--- a/http.c
+++ b/http.c
@@ -215,9 +215,14 @@ static CURL* get_curl_handle(void)
 
 void http_init(void)
 {
+	static int init = 0;
 	char *low_speed_limit;
 	char *low_speed_time;
 
+	if (init)
+		return;
+	init = 1;
+
 	curl_global_init(CURL_GLOBAL_ALL);
 
 	pragma_header = curl_slist_append(pragma_header, "Pragma: no-cache");
diff --git a/transport.c b/transport.c
index babaa21..1eb6d78 100644
--- a/transport.c
+++ b/transport.c
@@ -473,8 +473,6 @@ static struct ref *get_refs_via_curl(struct transport *transport)
 		return NULL;
 	}
 
-	http_cleanup();
-
 	data = buffer.buf;
 	start = NULL;
 	mid = data;
-- 
1.5.4.7.gd8534-dirty

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Anand Kumria, (Thu Feb 7, 6:15 am)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Dmitry Potapov, (Thu Feb 7, 7:23 pm)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Frank Lichtenheld, (Thu Feb 7, 10:23 am)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Linus Torvalds, (Thu Feb 7, 2:42 pm)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Jeff King, (Thu Feb 7, 4:40 pm)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Linus Torvalds, (Thu Feb 7, 5:01 pm)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Jeff King, (Thu Feb 7, 6:40 pm)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Dmitry Potapov, (Thu Feb 7, 5:53 pm)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Jeff King, (Thu Feb 7, 6:46 pm)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Martin Langhoff, (Thu Feb 7, 5:47 pm)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Frank Lichtenheld, (Thu Feb 7, 4:14 pm)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Linus Torvalds, (Thu Feb 7, 4:54 pm)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Anand Kumria, (Thu Feb 7, 5:36 pm)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Jeff King, (Thu Feb 7, 7:06 am)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Mike Hommey, (Thu Feb 7, 8:10 am)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Jeff King, (Thu Feb 7, 8:28 am)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Mike Hommey, (Thu Feb 7, 6:02 pm)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Jeff King, (Thu Feb 7, 8:32 pm)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Mike Hommey, (Fri Feb 8, 3:18 am)
Re: git-fetch in 1.5.4 fails versus 1.5.3.8, Mike Hommey, (Fri Feb 8, 3:34 am)
[PATCH] Work around curl-gnutls not liking to be reinitialized, Mike Hommey, (Fri Feb 8, 4:08 pm)
Re: [PATCH] Work around curl-gnutls not liking to be reiniti..., Johannes Schindelin, (Fri Feb 8, 5:53 pm)
Re: [PATCH v2] Work around curl-gnutls not liking to be rein..., Johannes Schindelin, (Fri Feb 8, 6:51 pm)