From 4026172cf619a8c7ea27159ab26d49ced7e9c0de Mon Sep 17 00:00:00 2001 From: hikerstk Date: Sun, 16 Oct 2011 13:06:40 +0000 Subject: [PATCH] Fixed another memory leak: stopping STK while icons are still downloading in the background. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10000 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/addons/addons_manager.cpp | 2 +- src/addons/network_http.cpp | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/addons/addons_manager.cpp b/src/addons/addons_manager.cpp index b5a65b3f3..97d76529c 100644 --- a/src/addons/addons_manager.cpp +++ b/src/addons/addons_manager.cpp @@ -293,7 +293,7 @@ void AddonsManager::downloadIcons() std::string save = "icons/"+icon; Request *r = network_http->downloadFileAsynchron(url, save, /*priority*/1, - /*manage_mem*/false); + /*manage_mem*/true); r->setAddonIconNotification(&addon); } else diff --git a/src/addons/network_http.cpp b/src/addons/network_http.cpp index 065dca8db..31fee4734 100644 --- a/src/addons/network_http.cpp +++ b/src/addons/network_http.cpp @@ -156,7 +156,6 @@ void *NetworkHttp::mainLoop(void *obj) // so it is certain that even me->m_current_request = me->m_all_requests.getData().top(); me->m_all_requests.getData().pop(); - me->m_all_requests.unlock(); if(UserConfigParams::logAddons()) { if(me->m_current_request->getCommand()==Request::HC_DOWNLOAD_FILE) @@ -171,13 +170,12 @@ void *NetworkHttp::mainLoop(void *obj) } if(me->m_current_request->getCommand()==Request::HC_QUIT) { - if(me->m_current_request->manageMemory()) - { - delete me->m_current_request; - me->m_current_request = NULL; - } + delete me->m_current_request; + me->m_current_request = NULL; break; } + + me->m_all_requests.unlock(); CURLcode status=CURLE_OK; switch(me->m_current_request->getCommand()) { @@ -209,6 +207,17 @@ void *NetworkHttp::mainLoop(void *obj) if(UserConfigParams::logAddons()) printf("[addons] Network exiting.\n"); + // At this stage we have the lock for m_all_requests + while(!me->m_all_requests.getData().empty()) + { + Request *r = me->m_all_requests.getData().top(); + me->m_all_requests.getData().pop(); + // Manage memory can be ignored here, all requests + // need to be freed. + delete r; + } + me->m_all_requests.unlock(); + pthread_exit(NULL); return 0; } // mainLoop