- 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
This commit is contained in:
alexey.lysiuk 2018-06-22 15:40:28 +03:00
parent eddb179e36
commit 9b4e8efcb9

View file

@ -36,6 +36,25 @@
struct MapData struct MapData
{ {
private: 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 struct MapLump
{ {
char Name[8] = { 0 }; char Name[8] = { 0 };
@ -48,13 +67,6 @@ public:
bool isText = false; bool isText = false;
bool InWad = false; bool InWad = false;
int lumpnum = -1; int lumpnum = -1;
FResourceFile * resource = nullptr;
~MapData()
{
if (resource != nullptr) delete resource;
resource = nullptr;
}
/* /*
void Seek(unsigned int lumpindex) void Seek(unsigned int lumpindex)