git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/1] remote-curl: unbreak http.extraHeader with custom allocators

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 5, 2019, 21:59 UTC
Message-ID
<d47a2aa5949a5dd3a10b89d9a77ebb89af6ba57e.1572991158.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.453.git.1572991158.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

In 93b980e58f5 (http: use xmalloc with cURL, 2019-08-15), we started to ask cURL to use `xmalloc()`, and if compiled with nedmalloc, that means implicitly a different allocator than the system one.

Which means that all of cURL's allocations and releases now _need_ to use that allocator.

However, the `http_options()` function used `slist_append()` to add any configured extra HTTP header(s) _before_ asking cURL to use `xmalloc()`, and `http_cleanup()` would release them _afterwards_, i.e. in the presence of custom allocators, cURL would attempt to use the wrong allocator to release the memory.

Let's fix this by moving the initialization _before_ the `http_options()` function is called.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 http.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/http.c b/http.c
index 27aa0a3192..13f50ba158 100644
--- a/http.c
+++ b/http.c
@@ -1062,6 +1062,9 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
 	char *normalized_url;
 	struct urlmatch_config config = { STRING_LIST_INIT_DUP };
 
+	if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK)
+		die("curl_global_init failed");
+
 	config.section = "http";
 	config.key = NULL;
 	config.collect_fn = http_options;
@@ -1101,9 +1104,6 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
 	}
 #endif
 
-	if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK)
-		die("curl_global_init failed");
-
 	http_proactive_auth = proactive_auth;
 
 	if (remote && remote->http_proxy)
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Jeff King
Message 2 of 17 in “remote-curl: unbreak http.extraHeader with custom allocators”
  1. 0/1 remote-curl: unbreak http.extraHeader with custom allocatorsJohannes Schindelin via GitGitGadget, Nov 5, 2019
  2. 1/1 remote-curl: unbreak http.extraHeader with custom allocatorsJohannes Schindelin via GitGitGadget, Nov 5, 2019
  3. Jeff KingNov 6, 2019
  4. Johannes SchindelinNov 6, 2019
  5. Junio C HamanoNov 6, 2019
  6. Johannes SchindelinNov 6, 2019
  7. Junio C HamanoNov 8, 2019
  8. Johannes SchindelinNov 8, 2019
  9. 0/1 remote-curl: unbreak http.extraHeader with custom allocatorsJohannes Schindelin via GitGitGadget, Nov 6, 2019
  10. 1/1 remote-curl: unbreak http.extraHeader with custom allocatorsJohannes Schindelin via GitGitGadget, Nov 6, 2019
  11. Jeff KingNov 6, 2019
  12. Junio C HamanoNov 6, 2019
  13. Johannes SchindelinNov 6, 2019
  14. Junio C HamanoNov 7, 2019
  15. Johannes SchindelinNov 7, 2019
  16. Junio C HamanoNov 8, 2019
  17. Junio C HamanoNov 6, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.