From dcf6d12ae11a960a26de710f35f6e936210f096b Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 9 Feb 2023 22:56:13 +0100 Subject: [PATCH] Fix memory leak in Curl util code 'curl_slist' pointer should be passed in as reference, as its destroyed elsewhere. --- r5dev/tier2/curlutils.cpp | 8 +++++--- r5dev/tier2/curlutils.h | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/r5dev/tier2/curlutils.cpp b/r5dev/tier2/curlutils.cpp index e88fb438..da1ba8fe 100644 --- a/r5dev/tier2/curlutils.cpp +++ b/r5dev/tier2/curlutils.cpp @@ -13,25 +13,26 @@ size_t CURLWriteStringCallback(char* contents, size_t size, size_t nmemb, void* return size * nmemb; } -CURL* CURLInitRequest(const string& hostname, const string& request, string& response, curl_slist* slist) +CURL* CURLInitRequest(const string& hostname, const string& request, string& response, curl_slist*& slist) { std::function fnError = [&](const char* errorMsg) { Error(eDLL_T::ENGINE, NO_ERROR, "CURL: %s\n", errorMsg); curl_slist_free_all(slist); - return nullptr; }; slist = curl_slist_append(slist, "Content-Type: application/json"); if (!slist) { fnError("Slist init failed"); + return nullptr; } CURL* curl = curl_easy_init(); if (!curl) { fnError("Easy init failed"); + return nullptr; } curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist); @@ -45,6 +46,7 @@ CURL* CURLInitRequest(const string& hostname, const string& request, string& res curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); curl_easy_setopt(curl, CURLOPT_VERBOSE, curl_debug->GetBool()); + curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L); if (!ssl_verify_peer->GetBool()) { @@ -54,7 +56,7 @@ CURL* CURLInitRequest(const string& hostname, const string& request, string& res return curl; } -CURLcode CURLSubmitRequest(CURL* curl, curl_slist* slist) +CURLcode CURLSubmitRequest(CURL* curl, curl_slist*& slist) { CURLcode res = curl_easy_perform(curl); curl_slist_free_all(slist); diff --git a/r5dev/tier2/curlutils.h b/r5dev/tier2/curlutils.h index eea03cca..b83978a4 100644 --- a/r5dev/tier2/curlutils.h +++ b/r5dev/tier2/curlutils.h @@ -3,8 +3,8 @@ size_t CURLWriteStringCallback(char* contents, size_t size, size_t nmemb, void* userp); -CURL* CURLInitRequest(const string& hostname, const string& request, string& response, curl_slist* slist); -CURLcode CURLSubmitRequest(CURL* curl, curl_slist* slist); +CURL* CURLInitRequest(const string& hostname, const string& request, string& response, curl_slist*& slist); +CURLcode CURLSubmitRequest(CURL* curl, curl_slist*& slist); CURLINFO CURLRetrieveInfo(CURL* curl); bool CURLHandleError(CURL* curl, CURLcode res, string& outMessage);