Skip to content

Commit

Permalink
fix memory leaks when loading stamps ('l') and viewing saves
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Apr 21, 2018
1 parent 22b9bf4 commit 6731fa1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
8 changes: 8 additions & 0 deletions src/client/requestbroker/ImageRequest.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/client/requestbroker/ImageRequest.h
Expand Up @@ -7,6 +7,7 @@ class ImageRequest: public RequestBroker::Request
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();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/game/GameModel.cpp
Expand Up @@ -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;
Expand Down
26 changes: 14 additions & 12 deletions src/gui/game/GameView.cpp
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/gui/preview/PreviewModel.cpp
Expand Up @@ -307,6 +307,7 @@ void PreviewModel::Update()
}
}
saveDataDownload = NULL;
free(ret);
}

if (saveInfoDownload && saveInfoDownload->CheckDone())
Expand Down Expand Up @@ -334,6 +335,7 @@ void PreviewModel::Update()
observers[i]->SaveLoadingError(Client::Ref().GetLastError());
}
saveInfoDownload = NULL;
free(ret);
}

if (commentsDownload && commentsDownload->CheckDone())
Expand All @@ -351,6 +353,7 @@ void PreviewModel::Update()
notifyCommentsPageChanged();

commentsDownload = NULL;
free(ret);
}
}

Expand Down

0 comments on commit 6731fa1

Please sign in to comment.