From 612e8bdaf62bd673cb6900f3c9d74a048035650f Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 11 Sep 2018 14:24:59 +0800 Subject: [PATCH] Keep http header of curl_slist* until the exit of stk to prevent memory leak --- src/online/http_request.cpp | 12 +++++++++--- src/online/http_request.hpp | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/online/http_request.cpp b/src/online/http_request.cpp index 8cc830165..252e93a70 100644 --- a/src/online/http_request.cpp +++ b/src/online/http_request.cpp @@ -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) diff --git a/src/online/http_request.hpp b/src/online/http_request.hpp index 095153376..72a143afa 100644 --- a/src/online/http_request.hpp +++ b/src/online/http_request.hpp @@ -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;