mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 21:29:06 +00:00
RequestServer: Free curl string lists and check result before setting
Previously, we leaked the `curl_slist`s on every request. This also validates the pointer we get from `curl_slist_append` before setting the option. Also, use the `set_option` helper for CURLOPT_RESOLVE as it will print when there is an error.
This commit is contained in:
parent
32358df13e
commit
c490118b6c
Notes:
github-actions[bot]
2024-12-01 10:36:30 +00:00
Author: https://github.com/rmg-x
Commit: c490118b6c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2649
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/awesomekling
1 changed files with 14 additions and 3 deletions
|
@ -70,6 +70,7 @@ static NonnullRefPtr<Resolver> default_resolver()
|
|||
struct ConnectionFromClient::ActiveRequest {
|
||||
CURLM* multi { nullptr };
|
||||
CURL* easy { nullptr };
|
||||
Vector<curl_slist*> curl_string_lists;
|
||||
i32 request_id { 0 };
|
||||
RefPtr<Core::Notifier> notifier;
|
||||
WeakPtr<ConnectionFromClient> client;
|
||||
|
@ -99,6 +100,9 @@ struct ConnectionFromClient::ActiveRequest {
|
|||
auto result = curl_multi_remove_handle(multi, easy);
|
||||
VERIFY(result == CURLM_OK);
|
||||
curl_easy_cleanup(easy);
|
||||
|
||||
for (auto* string_list : curl_string_lists)
|
||||
curl_slist_free_all(string_list);
|
||||
}
|
||||
|
||||
void flush_headers_if_needed()
|
||||
|
@ -421,7 +425,11 @@ void ConnectionFromClient::start_request(i32 request_id, ByteString const& metho
|
|||
auto header_string = ByteString::formatted("{}: {}", header.name, header.value);
|
||||
curl_headers = curl_slist_append(curl_headers, header_string.characters());
|
||||
}
|
||||
set_option(CURLOPT_HTTPHEADER, curl_headers);
|
||||
|
||||
if (curl_headers) {
|
||||
set_option(CURLOPT_HTTPHEADER, curl_headers);
|
||||
request->curl_string_lists.append(curl_headers);
|
||||
}
|
||||
|
||||
// FIXME: Set up proxy if applicable
|
||||
(void)proxy_data;
|
||||
|
@ -446,8 +454,11 @@ void ConnectionFromClient::start_request(i32 request_id, ByteString const& metho
|
|||
}
|
||||
|
||||
auto formatted_address = resolve_opt_builder.to_byte_string();
|
||||
curl_slist* resolve_list = curl_slist_append(nullptr, formatted_address.characters());
|
||||
curl_easy_setopt(easy, CURLOPT_RESOLVE, resolve_list);
|
||||
if (curl_slist* resolve_list = curl_slist_append(nullptr, formatted_address.characters())) {
|
||||
set_option(CURLOPT_RESOLVE, resolve_list);
|
||||
request->curl_string_lists.append(resolve_list);
|
||||
} else
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
auto result = curl_multi_add_handle(m_curl_multi, easy);
|
||||
VERIFY(result == CURLM_OK);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue