Skip to content
Permalink
Browse files

fix segv if Lua handler is invalid

  • Loading branch information...
rtri
rtri committed Sep 2, 2019
1 parent 38fb734 commit 324939f7119ee03f59499d5a6d30f6c3ef27a2c9
Showing with 30 additions and 28 deletions.
  1. +30 −28 rts/Lua/LuaDefs.h
@@ -85,43 +85,45 @@ namespace {



#define DECL_LOAD_HANDLER(HandlerType, HandlerInstance) \
bool HandlerType::LoadHandler() { \
std::lock_guard<spring::mutex> lk(m_singleton); \
\
if (HandlerInstance != nullptr) \
return (HandlerInstance->IsValid()); \
if (!HandlerType::CanLoadHandler()) \
return false; \
\
HandlerInstance = new HandlerType(); \
HandlerInstance->CollectGarbage(true); \
return (HandlerInstance->IsValid()); \
#define DECL_LOAD_HANDLER(HandlerType, handlerInst) \
bool HandlerType::LoadHandler() { \
std::lock_guard<spring::mutex> lk(m_singleton); \
\
if (handlerInst != nullptr) \
return (handlerInst->IsValid()); \
if (!HandlerType::CanLoadHandler()) \
return false; \
\
if (!(handlerInst = new HandlerType())->IsValid()) \
return false; \
\
return (handlerInst->CollectGarbage(true), true); \
}

#define DECL_LOAD_SPLIT_HANDLER(HandlerType, HandlerInstance) \
bool HandlerType::LoadHandler(bool onlySynced) { \
std::lock_guard<spring::mutex> lk(m_singleton); \
\
if (HandlerInstance != nullptr) \
return (HandlerInstance->IsValid()); \
if (!HandlerType::CanLoadHandler()) \
return false; \
\
HandlerInstance = new HandlerType(onlySynced); \
HandlerInstance->CollectGarbage(true); \
return (HandlerInstance->IsValid()); \
#define DECL_LOAD_SPLIT_HANDLER(HandlerType, handlerInst) \
bool HandlerType::LoadHandler(bool onlySynced) { \
std::lock_guard<spring::mutex> lk(m_singleton); \
\
if (handlerInst != nullptr) \
return (handlerInst->IsValid()); \
if (!HandlerType::CanLoadHandler()) \
return false; \
\
if (!(handlerInst = new HandlerType(onlySynced))->IsValid()) \
return false; \
\
return (handlerInst->CollectGarbage(true), true); \
}

#define DECL_FREE_HANDLER(HandlerType, HandlerInstance) \
#define DECL_FREE_HANDLER(HandlerType, handlerInst) \
bool HandlerType::FreeHandler() { \
std::lock_guard<spring::mutex> lk(m_singleton); \
\
if (HandlerInstance == nullptr) \
if (handlerInst == nullptr) \
return false; \
\
auto* inst = HandlerInstance; \
HandlerInstance = nullptr; \
HandlerType* inst = handlerInst; \
handlerInst = nullptr; \
inst->KillLua(true); \
delete inst; \
return true; \

0 comments on commit 324939f

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