Fix: Freeing LanguagePack with wrong size.
This commit is contained in:
@@ -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()) */
|
||||
|
Reference in New Issue
Block a user