From a92ba66650c2ba76593bc6667dffd8652e60f3ef Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Fri, 11 Mar 2022 21:12:55 +0100 Subject: [PATCH] Repo UI: Do not leak CURL on exception. --- source/main/gui/panels/GUI_RepositorySelector.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/source/main/gui/panels/GUI_RepositorySelector.cpp b/source/main/gui/panels/GUI_RepositorySelector.cpp index df98272149..2c5adaa2dc 100644 --- a/source/main/gui/panels/GUI_RepositorySelector.cpp +++ b/source/main/gui/panels/GUI_RepositorySelector.cpp @@ -308,13 +308,12 @@ void DownloadResourceFile(int resource_id, std::string filename, int id) RepoProgressContext progress_context; progress_context.filename = filename; + CURL *curl = curl_easy_init(); try // We write using Ogre::DataStream which throws exceptions { // smart pointer - closes stream automatically Ogre::DataStreamPtr datastream = Ogre::ResourceGroupManager::getSingleton().createResource(file, RGN_REPO); - CURL *curl = curl_easy_init(); - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); #ifdef _WIN32 @@ -326,9 +325,6 @@ void DownloadResourceFile(int resource_id, std::string filename, int id) curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &progress_context); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, CurlProgressFunc); // Use our progress window curl_easy_perform(curl); - - curl_easy_cleanup(curl); - curl = nullptr; } catch (Ogre::Exception& oex) { @@ -337,6 +333,8 @@ void DownloadResourceFile(int resource_id, std::string filename, int id) fmt::format("Repository UI: cannot download file '{}' - {}", url, oex.getFullDescription())); } + curl_easy_cleanup(curl); + curl = nullptr; App::GetGameContext()->PushMessage( Message(MSG_GUI_DOWNLOAD_FINISHED));