Keep http header of curl_slist* until the exit of stk to prevent memory leak

This commit is contained in:
Benau 2018-09-11 14:24:59 +08:00
parent dd15947aa1
commit 612e8bdaf6
2 changed files with 11 additions and 3 deletions

View File

@ -31,6 +31,7 @@
namespace Online
{
std::string HTTPRequest::m_cert_location;
struct curl_slist* HTTPRequest::m_http_header = NULL;
const std::string API::USER_PATH = "user/";
const std::string API::SERVER_PATH = "server/";
@ -100,6 +101,11 @@ namespace Online
m_cert_location =
file_manager->getAsset("addons.supertuxkart.net.pem");
}
if (m_http_header == NULL)
{
m_http_header = curl_slist_append(m_http_header,
"Host: addons.supertuxkart.net");
}
m_disable_sending_log = false;
} // init
@ -182,9 +188,9 @@ namespace Online
if (m_url.substr(0, 8) == "https://")
{
// https, load certificate info
struct curl_slist *chunk = NULL;
chunk = curl_slist_append(chunk, "Host: addons.supertuxkart.net");
curl_easy_setopt(m_curl_session, CURLOPT_HTTPHEADER, chunk);
assert(m_http_header != NULL);
curl_easy_setopt(m_curl_session, CURLOPT_HTTPHEADER,
m_http_header);
CURLcode error = curl_easy_setopt(m_curl_session, CURLOPT_CAINFO,
m_cert_location.c_str());
if (error != CURLE_OK)

View File

@ -72,6 +72,8 @@ namespace Online
std::string m_string_buffer;
static std::string m_cert_location;
static struct curl_slist* m_http_header;
protected:
bool m_disable_sending_log;