Skip to content

Commit

Permalink
Repo UI: Do not leak CURL on exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp authored and tritonas00 committed Mar 12, 2022
1 parent 888147a commit a92ba66
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions source/main/gui/panels/GUI_RepositorySelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
{
Expand All @@ -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));
Expand Down

0 comments on commit a92ba66

Please # to comment.