@matheusbsbs / matheus-bagliano / commits / 3278cd0a39
Fork 0

Properly cleanup in http_cleanup so builtin-fetch does not segfault

Junio and I both noticed that the new builtin-fetch was segfaulting immediately on http/https/ftp style URLs (those that went through libcurl and the commit walker). Although the builtin-fetch changes in this area were really just minor refactorings there was one major change made: we invoked http_init(), http_cleanup() then http_init() again in the same process. When we call curl_easy_cleanup() on each active_request_slot we are telling libcurl we did not want that buffer to be used again. Unfortunately we did not also deallocate the active_request_slot itself nor did we NULL out active_queue_head. This lead us to attempt to reuse these cleaned up libcurl handles when we later tried to invoke http_init() a second time to reactivate the curl library. The next file get operation then immediately segfaulted on most versions of libcurl. Properly freeing our own buffers and clearing the list causes us to reinitialize the curl buffers again if/when we need to use libcurl from within this same process. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shawn O. Pearce committed Sep 15, 2007 at 03:23 UTC 3278cd0a39c30c6c3082fc5feed0f9bd98b5f628
1 file changed +5 -2
http.c
+5 -2
@@ -276,6 +276,7 @@ void http_cleanup(void)
276 #endif
277
278 while (slot != NULL) {
279 + struct active_request_slot *next = slot->next;
280 #ifdef USE_CURL_MULTI
281 if (slot->in_use) {
282 curl_easy_getinfo(slot->curl,
@@ -287,8 +288,10 @@ void http_cleanup(void)
288 #endif
289 if (slot->curl != NULL)
290 curl_easy_cleanup(slot->curl);
290 - slot = slot->next;
291 + free(slot);
292 + slot = next;
293 }
294 + active_queue_head = NULL;
295
296 #ifndef NO_CURL_EASY_DUPHANDLE
297 curl_easy_cleanup(curl_default);
@@ -300,7 +303,7 @@ void http_cleanup(void)
303 curl_global_cleanup();
304
305 curl_slist_free_all(pragma_header);
303 - pragma_header = NULL;
306 + pragma_header = NULL;
307 }
308
309 struct active_request_slot *get_active_slot(void)