fix memory leaks when loading stamps ('l') and viewing saves

This commit is contained in:
jacob1 2018-04-21 00:15:15 -04:00
parent 22b9bf4953
commit 6731fa16b7
5 changed files with 28 additions and 14 deletions

View File

@ -45,6 +45,7 @@ RequestBroker::ProcessResponse ImageRequest::Process(RequestBroker & rb)
char * data;
int status, data_size, imgw, imgh;
data = http_async_req_stop(HTTPContext, &status, &data_size);
started = false;
if (status == 200 && data)
{
@ -107,6 +108,7 @@ RequestBroker::ProcessResponse ImageRequest::Process(RequestBroker & rb)
std::cout << typeid(*this).name() << " Creating new request for " << URL << std::endl;
#endif*/
HTTPContext = http_async_req_start(NULL, (char *)URL.c_str(), NULL, 0, 0);
started = true;
RequestTime = time(NULL);
}
}
@ -147,4 +149,10 @@ void ImageRequest::Cleanup()
delete ((VideoBuffer*)ResultObject);
ResultObject = NULL;
}
if (HTTPContext && started)
{
http_force_close(HTTPContext);
http_async_req_stop(HTTPContext, nullptr, nullptr);
started = false;
}
}

View File

@ -7,6 +7,7 @@ public:
std::string URL;
int RequestTime;
void * HTTPContext;
bool started = false;
ImageRequest(std::string url, int width, int height, ListenerHandle listener, int identifier = 0);
virtual RequestBroker::ProcessResponse Process(RequestBroker & rb);
virtual ~ImageRequest();

View File

@ -1021,10 +1021,10 @@ void GameModel::ClearSimulation()
void GameModel::SetPlaceSave(GameSave * save)
{
if(save != placeSave)
if (save != placeSave)
{
delete placeSave;
if(save)
if (save)
placeSave = new GameSave(*save);
else
placeSave = NULL;

View File

@ -1,28 +1,28 @@
#include <sstream>
#include <iomanip>
#include <algorithm>
#include "GameView.h"
#include "Config.h"
#include "gui/Style.h"
#include "GameView.h"
#include "Favorite.h"
#include "Format.h"
#include "IntroText.h"
#include "QuickOptions.h"
#include "DecorationTool.h"
#include "client/SaveFile.h"
#include "graphics/Graphics.h"
#include "gui/interface/Window.h"
#include "gui/Style.h"
#include "gui/dialogues/ConfirmPrompt.h"
#include "gui/dialogues/InformationMessage.h"
#include "gui/interface/Button.h"
#include "gui/interface/Colour.h"
#include "gui/interface/Keys.h"
#include "gui/interface/Mouse.h"
#include "gui/interface/Slider.h"
#include "gui/interface/Window.h"
#include "gui/search/Thumbnail.h"
#include "simulation/SaveRenderer.h"
#include "simulation/SimulationData.h"
#include "gui/dialogues/InformationMessage.h"
#include "gui/dialogues/ConfirmPrompt.h"
#include "client/SaveFile.h"
#include "Format.h"
#include "QuickOptions.h"
#include "IntroText.h"
#include "DecorationTool.h"
#include "Favorite.h"
class SplitButton;
@ -1612,7 +1612,9 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
std::vector<std::string> stampList = Client::Ref().GetStamps(0, 1);
if (stampList.size())
{
c->LoadStamp(Client::Ref().GetStamp(stampList[0])->GetGameSave());
SaveFile *saveFile = Client::Ref().GetStamp(stampList[0]);
c->LoadStamp(saveFile->GetGameSave());
delete saveFile;
selectPoint1 = selectPoint2 = mousePosition;
isMouseDown = false;
break;

View File

@ -307,6 +307,7 @@ void PreviewModel::Update()
}
}
saveDataDownload = NULL;
free(ret);
}
if (saveInfoDownload && saveInfoDownload->CheckDone())
@ -334,6 +335,7 @@ void PreviewModel::Update()
observers[i]->SaveLoadingError(Client::Ref().GetLastError());
}
saveInfoDownload = NULL;
free(ret);
}
if (commentsDownload && commentsDownload->CheckDone())
@ -351,6 +353,7 @@ void PreviewModel::Update()
notifyCommentsPageChanged();
commentsDownload = NULL;
free(ret);
}
}