1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-16 03:23:15 +01:00

Merge pull request #5510 from ceeac/memleaks

Fix memory leaks
This commit is contained in:
Ted John
2017-05-27 10:28:45 +01:00
committed by GitHub
5 changed files with 16 additions and 5 deletions

View File

@@ -77,6 +77,7 @@ Includes all git commit authors. Aliases are GitHub user names.
* Jake Breen (Haekb)
* Marco Benzi Tobar (Lisergishnu)
* Richard Jenkins (rwjuk)
* (ceeac)
## Toolchain
* (Balletie) - macOS

View File

@@ -44,7 +44,10 @@ namespace Path
std::string GetDirectory(const std::string &path)
{
return GetDirectory(path.c_str());
const utf8* directory = GetDirectory(path.c_str());
std::string result(directory);
Memory::Free(directory);
return result;
}
utf8 * GetDirectory(const utf8 * path)

View File

@@ -54,7 +54,7 @@ extern "C"
TitleSequence * LoadTitleSequence(const utf8 * path)
{
size_t scriptLength;
char * script;
utf8 * script;
std::vector<utf8 *> saves;
bool isZip;
@@ -70,7 +70,7 @@ extern "C"
return nullptr;
}
script = (char *)zip->GetFileData("script.txt", &scriptLength);
script = (utf8 *)zip->GetFileData("script.txt", &scriptLength);
if (script == nullptr)
{
Console::Error::WriteLine("Unable to open script.txt in '%s'", path);
@@ -88,7 +88,7 @@ extern "C"
utf8 scriptPath[MAX_PATH];
String::Set(scriptPath, sizeof(scriptPath), path);
Path::Append(scriptPath, sizeof(scriptPath), "script.txt");
script = (char *)ReadScriptFile(scriptPath, &scriptLength);
script = (utf8 *)ReadScriptFile(scriptPath, &scriptLength);
if (script == nullptr)
{
Console::Error::WriteLine("Unable to open '%s'", scriptPath);
@@ -100,6 +100,7 @@ extern "C"
}
std::vector<TitleCommand> commands = LegacyScriptRead(script, scriptLength, saves);
Memory::Free(script);
TitleSequence * seq = CreateTitleSequence();
seq->Name = Path::GetFileNameWithoutExtension(path);
@@ -165,6 +166,7 @@ extern "C"
{
Memory::Free(handle->HintPath);
delete ((IStream *)handle->Stream);
Memory::Free(handle);
}
}

View File

@@ -88,6 +88,11 @@ extern "C"
void FreeTitleSequence(TitleSequence * seq);
TitleSequenceParkHandle * TitleSequenceGetParkHandle(TitleSequence * seq, size_t index);
/**
* Close a title sequence park handle.
* The pointer to the handle is invalid after calling this function.
*/
void TitleSequenceCloseParkHandle(TitleSequenceParkHandle * handle);
bool TileSequenceSave(TitleSequence * seq);
bool TileSequenceAddPark(TitleSequence * seq, const utf8 * path, const utf8 * name);

View File

@@ -267,7 +267,7 @@ namespace TitleSequenceManager
if (item.PredefinedIndex != PREDEFINED_INDEX_CUSTOM)
{
rct_string_id stringId = PredefinedSequences[item.PredefinedIndex].StringId;
item.Name = String::Duplicate(language_get_string(stringId));
item.Name = language_get_string(stringId);
}
item.IsZip = isZip;
_items.push_back(item);