diff options
author | milek7 <me@milek7.pl> | 2021-03-28 00:12:32 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-04-02 10:12:25 +0200 |
commit | 295f34a9dfea9b141a3aefaee582cd6386779f29 (patch) | |
tree | c1e6442fd9213e253e84082cecc5967e0b7427b1 /src/strings.cpp | |
parent | dd798d688b7e9ea6c7d4d01aea976dde5ec75f60 (diff) | |
download | openttd-295f34a9dfea9b141a3aefaee582cd6386779f29.tar.xz |
Fix: Freeing LanguagePack with wrong size.
Diffstat (limited to 'src/strings.cpp')
-rw-r--r-- | src/strings.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/strings.cpp b/src/strings.cpp index 02ca30f23..08e826141 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -185,8 +185,16 @@ struct LanguagePack : public LanguagePackHeader { char data[]; // list of strings }; +struct LanguagePackDeleter { + void operator()(LanguagePack *langpack) + { + /* LanguagePack is in fact reinterpreted char[], we need to reinterpret it back to free it properly. */ + delete[] reinterpret_cast<char*>(langpack); + } +}; + struct LoadedLanguagePack { - std::unique_ptr<LanguagePack> langpack; + std::unique_ptr<LanguagePack, LanguagePackDeleter> langpack; std::vector<char *> offsets; @@ -1713,7 +1721,7 @@ bool ReadLanguagePack(const LanguageMetadata *lang) { /* Current language pack */ size_t len = 0; - std::unique_ptr<LanguagePack> lang_pack(reinterpret_cast<LanguagePack *>(ReadFileToMem(lang->file, len, 1U << 20).release())); + std::unique_ptr<LanguagePack, LanguagePackDeleter> lang_pack(reinterpret_cast<LanguagePack *>(ReadFileToMem(lang->file, len, 1U << 20).release())); if (!lang_pack) return false; /* End of read data (+ terminating zero added in ReadFileToMem()) */ |