From 850b10f1fdfec11d0df10f8caf75ee35cfe13848 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 28 Sep 2020 17:26:53 +0300 Subject: [PATCH] Fix memory leak Co-authored-by: Gabriel Guedes --- src/openrct2/title/TitleSequence.cpp | 2 +- src/openrct2/title/TitleSequenceManager.cpp | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/openrct2/title/TitleSequence.cpp b/src/openrct2/title/TitleSequence.cpp index ba603ffdfa..67a70760c9 100644 --- a/src/openrct2/title/TitleSequence.cpp +++ b/src/openrct2/title/TitleSequence.cpp @@ -90,7 +90,7 @@ std::unique_ptr LoadTitleSequence(const utf8* path) auto seq = CreateTitleSequence(); seq->Name = Path::GetFileNameWithoutExtension(std::string(path)); - seq->Path = String::Duplicate(path); + seq->Path = path; for (auto* save : saves) { seq->Saves.push_back(save); diff --git a/src/openrct2/title/TitleSequenceManager.cpp b/src/openrct2/title/TitleSequenceManager.cpp index c7817394e4..413c7e66a3 100644 --- a/src/openrct2/title/TitleSequenceManager.cpp +++ b/src/openrct2/title/TitleSequenceManager.cpp @@ -137,10 +137,9 @@ namespace TitleSequenceManager size_t CreateItem(const utf8* name) { - std::string path = GetNewTitleSequencePath(std::string(name), true); auto seq = CreateTitleSequence(); seq->Name = name; - seq->Path = String::Duplicate(path.c_str()); + seq->Path = GetNewTitleSequencePath(std::string(name), true); seq->IsZip = true; bool success = TitleSequenceSave(*seq); @@ -148,9 +147,9 @@ namespace TitleSequenceManager size_t index = SIZE_MAX; if (success) { - AddSequence(path.c_str()); + AddSequence(seq->Path.c_str()); SortSequences(); - index = FindItemIndexByPath(path.c_str()); + index = FindItemIndexByPath(seq->Path.c_str()); } return index; }