summaryrefslogtreecommitdiff
path: root/src/fileio.cpp
diff options
context:
space:
mode:
authormilek7 <me@milek7.pl>2021-03-28 00:12:32 +0100
committerMichael Lutz <michi@icosahedron.de>2021-04-02 10:12:25 +0200
commit295f34a9dfea9b141a3aefaee582cd6386779f29 (patch)
treec1e6442fd9213e253e84082cecc5967e0b7427b1 /src/fileio.cpp
parentdd798d688b7e9ea6c7d4d01aea976dde5ec75f60 (diff)
downloadopenttd-295f34a9dfea9b141a3aefaee582cd6386779f29.tar.xz
Fix: Freeing LanguagePack with wrong size.
Diffstat (limited to 'src/fileio.cpp')
-rw-r--r--src/fileio.cpp7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp
index 9a9e7e05d..6b33f8aa2 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -1259,7 +1259,7 @@ void SanitizeFilename(char *filename)
* @return Pointer to new memory containing the loaded data, or \c nullptr if loading failed.
* @note If \a maxsize less than the length of the file, loading fails.
*/
-std::unique_ptr<char> ReadFileToMem(const std::string &filename, size_t &lenp, size_t maxsize)
+std::unique_ptr<char[]> ReadFileToMem(const std::string &filename, size_t &lenp, size_t maxsize)
{
FILE *in = fopen(filename.c_str(), "rb");
if (in == nullptr) return nullptr;
@@ -1271,10 +1271,7 @@ std::unique_ptr<char> ReadFileToMem(const std::string &filename, size_t &lenp, s
fseek(in, 0, SEEK_SET);
if (len > maxsize) return nullptr;
- /* std::unique_ptr assumes new/delete unless a custom deleter is supplied.
- * As we don't want to have to carry that deleter all over the place, use
- * new directly to allocate the memory instead of malloc. */
- std::unique_ptr<char> mem(static_cast<char *>(::operator new(len + 1)));
+ std::unique_ptr<char[]> mem = std::make_unique<char[]>(len + 1);
mem.get()[len] = 0;
if (fread(mem.get(), len, 1, in) != 1) return nullptr;