Skip to content

Commit f3053a5

Browse files
committed
remote-curl: unbreak http.extraHeader with custom allocators
In 93b980e (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. A naïve attempt at fixing this would move the call to `curl_global_init()` _before_ the config is parsed (i.e. before that call to `slist_append()`). However, that does work, as we _also_ parse the config setting `http.sslbackend` and if found, call `curl_global_sslset()` which *must* be called before `curl_global_init()`, for details see: https://curl.haxx.se/libcurl/c/curl_global_sslset.html So let's instead make the config parsing entirely independent from cURL's data structures. Incidentally, this deletes two more lines than it introduces, which is nice. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent b944c5b commit f3053a5

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

http.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static unsigned long empty_auth_useless =
150150

151151
static struct curl_slist *pragma_header;
152152
static struct curl_slist *no_pragma_header;
153-
static struct curl_slist *extra_http_headers;
153+
static struct string_list extra_http_headers = STRING_LIST_INIT_DUP;
154154

155155
static struct active_request_slot *active_queue_head;
156156

@@ -414,11 +414,9 @@ static int http_options(const char *var, const char *value, void *cb)
414414
if (!value) {
415415
return config_error_nonbool(var);
416416
} else if (!*value) {
417-
curl_slist_free_all(extra_http_headers);
418-
extra_http_headers = NULL;
417+
string_list_clear(&extra_http_headers, 0);
419418
} else {
420-
extra_http_headers =
421-
curl_slist_append(extra_http_headers, value);
419+
string_list_append(&extra_http_headers, value);
422420
}
423421
return 0;
424422
}
@@ -1199,8 +1197,7 @@ void http_cleanup(void)
11991197
#endif
12001198
curl_global_cleanup();
12011199

1202-
curl_slist_free_all(extra_http_headers);
1203-
extra_http_headers = NULL;
1200+
string_list_clear(&extra_http_headers, 0);
12041201

12051202
curl_slist_free_all(pragma_header);
12061203
pragma_header = NULL;
@@ -1624,10 +1621,11 @@ int run_one_slot(struct active_request_slot *slot,
16241621

16251622
struct curl_slist *http_copy_default_headers(void)
16261623
{
1627-
struct curl_slist *headers = NULL, *h;
1624+
struct curl_slist *headers = NULL;
1625+
const struct string_list_item *item;
16281626

1629-
for (h = extra_http_headers; h; h = h->next)
1630-
headers = curl_slist_append(headers, h->data);
1627+
for_each_string_list_item(item, &extra_http_headers)
1628+
headers = curl_slist_append(headers, item->string);
16311629

16321630
return headers;
16331631
}

0 commit comments

Comments
 (0)