- fixed potential access to freed memory on map loading

MapData could destruct FResourceLump objects before accessing them
Loading of map .wad from .pk3 file is example of this case

https://forum.zdoom.org/viewtopic.php?t=60972
(cherry picked from commit 9b4e8efcb9)
This commit is contained in:
alexey.lysiuk 2018-06-22 15:40:28 +03:00 committed by drfrag666
parent b927ac6783
commit b9e7eaac26

View file

@ -36,6 +36,25 @@
struct MapData
{
private:
struct ResourceHolder
{
FResourceFile *data = nullptr;
~ResourceHolder()
{
delete data;
}
ResourceHolder &operator=(FResourceFile *other) { data = other; return *this; }
FResourceFile *operator->() { return data; }
operator FResourceFile *() const { return data; }
};
// The order of members here is important
// Resource should be destructed after MapLumps as readers may share FResourceLump objects
// For example, this is the case when map .wad is loaded from .pk3 file
ResourceHolder resource;
struct MapLump
{
char Name[8] = { 0 };
@ -48,13 +67,6 @@ public:
bool isText = false;
bool InWad = false;
int lumpnum = -1;
FResourceFile * resource = nullptr;
~MapData()
{
if (resource != nullptr) delete resource;
resource = nullptr;
}
/*
void Seek(unsigned int lumpindex)