Skip to content
Permalink
Browse files

Fix crash in CRegisteredCommands::TakeOutTheTrash

Solves crash offset 0011117c (see offset notes for details)
  • Loading branch information...
botder committed Sep 25, 2019
1 parent 381d74d commit 5b07e4e3a4cef04c691e76ed89f3851c0fa992b7
@@ -71,7 +71,7 @@ bool CRegisteredCommands::RemoveCommand(CLuaMain* pLuaMain, const char* szKey)
// Delete it and remove it from our list
if (m_bIteratingList)
{
m_TrashCan.push_back(*iter);
m_TrashCan.emplace(*iter);
}
else
{
@@ -254,13 +254,11 @@ void CRegisteredCommands::GetCommands(lua_State* luaVM, CLuaMain* pTargetLuaMain

void CRegisteredCommands::TakeOutTheTrash()
{
list<SCommand*>::iterator iter = m_TrashCan.begin();
for (; iter != m_TrashCan.end(); iter++)
for (SCommand* command : m_TrashCan)
{
SCommand* pCommand = *iter;
if (!m_Commands.empty())
m_Commands.remove(pCommand);
delete pCommand;
m_Commands.remove(command);
delete command;
}

m_TrashCan.clear();
}
@@ -11,6 +11,7 @@
#pragma once

#include <list>
#include <unordered_set>

#define MAX_REGISTERED_COMMAND_LENGTH 64
#define MAX_REGISTERED_COMMANDHANDLER_LENGTH 64
@@ -47,7 +48,7 @@ class CRegisteredCommands

void TakeOutTheTrash();

std::list<SCommand*> m_Commands;
std::list<SCommand*> m_TrashCan;
bool m_bIteratingList;
std::list<SCommand*> m_Commands;
std::unordered_set<SCommand*> m_TrashCan;
bool m_bIteratingList;
};
@@ -76,7 +76,7 @@ bool CRegisteredCommands::RemoveCommand(CLuaMain* pLuaMain, const char* szKey, c
// Delete it and remove it from our list
if (m_bIteratingList)
{
m_TrashCan.push_back(*iter);
m_TrashCan.emplace(*iter);
++iter;
}
else
@@ -296,12 +296,10 @@ void CRegisteredCommands::GetCommands(lua_State* luaVM, CLuaMain* pTargetLuaMain

void CRegisteredCommands::TakeOutTheTrash()
{
list<SCommand*>::iterator iter = m_TrashCan.begin();

for (; iter != m_TrashCan.end(); iter++)
for (SCommand* command : m_TrashCan)
{
m_Commands.remove(*iter);
delete *iter;
m_Commands.remove(command);
delete command;
}

m_TrashCan.clear();
@@ -12,6 +12,7 @@
#pragma once

#include <list>
#include <unordered_set>

#define MAX_REGISTERED_COMMAND_LENGTH 64
#define MAX_REGISTERED_COMMANDHANDLER_LENGTH 64
@@ -49,9 +50,9 @@ class CRegisteredCommands

void TakeOutTheTrash();

list<SCommand*> m_Commands;
list<SCommand*> m_TrashCan;
bool m_bIteratingList;
std::list<SCommand*> m_Commands;
std::unordered_set<SCommand*> m_TrashCan;
bool m_bIteratingList;

class CAccessControlListManager* m_pACLManager;
};

0 comments on commit 5b07e4e

Please sign in to comment.
You can’t perform that action at this time.