1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-04 13:42:55 +01:00

Merge pull request #7792 from oystedal/oystedal/string-memleaks

Fix memory leaks related to pointer assignment to std::string
This commit is contained in:
Michał Janiszewski
2018-07-21 19:56:55 +02:00
committed by GitHub
5 changed files with 15 additions and 5 deletions

View File

@@ -112,6 +112,7 @@ The following people are not part of the development team, but have been contrib
* Patrick Martinez (martip23)
* Andy Ford (AndyTWF)
* Matthew Beaudin (mattbeaudin)
* Øystein Dale (oystedal)
## Toolchain
* (Balletie) - macOS

View File

@@ -354,7 +354,7 @@ private:
sb.Append(&c, 1);
}
}
return std::string(sb.GetString());
return sb.GetStdString();
}
std::string GetLine(size_t index)

View File

@@ -10,6 +10,7 @@
#pragma once
#include <algorithm>
#include <string>
#include "../common.h"
#include "Math.hpp"
@@ -132,6 +133,14 @@ public:
return result;
}
/**
* Returns the current string buffer as a standard string.
*/
std::string GetStdString() const
{
return std::string(_buffer, _length);
}
/**
* Gets the current state of the StringBuilder. Warning: this represents the StringBuilder's current working buffer and will
* be deallocated when the StringBuilder is destructed.

View File

@@ -389,7 +389,7 @@ private:
}
if (sb.GetLength() == 8)
{
_currentGroup = sb.GetString();
_currentGroup = sb.GetStdString();
_currentObjectOverride = GetObjectOverride(_currentGroup);
_currentScenarioOverride = nullptr;
if (_currentObjectOverride == nullptr)
@@ -432,7 +432,7 @@ private:
if (closedCorrectly)
{
_currentGroup = sb.GetString();
_currentGroup = sb.GetStdString();
_currentObjectOverride = nullptr;
_currentScenarioOverride = GetScenarioOverride(_currentGroup);
if (_currentScenarioOverride == nullptr)

View File

@@ -156,8 +156,8 @@ protected:
ObjectRepositoryItem item;
item.ObjectEntry = stream->ReadValue<rct_object_entry>();
item.Path = stream->ReadString();
item.Name = stream->ReadString();
item.Path = stream->ReadStdString();
item.Name = stream->ReadStdString();
switch (object_entry_get_type(&item.ObjectEntry)) {
case OBJECT_TYPE_RIDE: