mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-16 17:41:19 +00:00
- 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:
parent
b927ac6783
commit
b9e7eaac26
1 changed files with 19 additions and 7 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue