1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Fix double free and use of dead reference when saving (#445)

This commit is contained in:
karliss 2018-04-07 18:21:28 +03:00 committed by ArseniyShestakov
parent 4af288aee4
commit ce0b4b222d
2 changed files with 6 additions and 7 deletions

View File

@ -32,7 +32,7 @@ CSavingScreen::CSavingScreen()
center(pos);
// TODO: we should really use std::shared_ptr for passing StartInfo around.
localSi = new StartInfo(*LOCPLINT->cb->getStartInfo());
localMi = new CMapInfo();
localMi = std::make_shared<CMapInfo>();
localMi->mapHeader = std::unique_ptr<CMapHeader>(new CMapHeader(*LOCPLINT->cb->getMapHeader()));
tabSel = std::make_shared<SelectionTab>(screenType);
@ -46,12 +46,11 @@ CSavingScreen::CSavingScreen()
CSavingScreen::~CSavingScreen()
{
vstd::clear_pointer(localMi);
}
const CMapInfo * CSavingScreen::getMapInfo()
{
return localMi;
return localMi.get();
}
const StartInfo * CSavingScreen::getStartInfo()
@ -61,10 +60,10 @@ const StartInfo * CSavingScreen::getStartInfo()
void CSavingScreen::changeSelection(std::shared_ptr<CMapInfo> to)
{
if(localMi == to.get())
if(localMi == to)
return;
localMi = to.get();
localMi = to;
localSi = localMi->scenarioOptionsOfSave;
card->changeSelection();
}
@ -76,7 +75,7 @@ void CSavingScreen::saveGame()
std::string path = "Saves/" + tabSel->inputName->text;
auto overWrite = [&]() -> void
auto overWrite = [this, path]() -> void
{
Settings lastSave = settings.write["general"]["lastSave"];
lastSave->String() = path;

View File

@ -19,7 +19,7 @@ class CSavingScreen : public CSelectionBase
{
public:
const StartInfo * localSi;
CMapInfo * localMi;
std::shared_ptr<CMapInfo> localMi;
CSavingScreen();
~CSavingScreen();