1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-18 11:19:10 +00:00

Fix leak check race condition, and remove an unintentional circular ref

This commit is contained in:
2014-06-01 11:18:51 -07:00
parent 7f4701cc1a
commit 39867610a2
2 changed files with 11 additions and 5 deletions

View File

@ -54,6 +54,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#if (REFCOUNT_DEBUGGING == REFCOUNT_DBG_LEAKS) || (REFCOUNT_DEBUGGING == REFCOUNT_DBG_ALL)
#include <unordered_set>
#include <mutex>
#include "plFormat.h"
#include "hsWindows.h"
@ -61,12 +62,15 @@ template <class _RefType>
struct _RefCountLeakCheck
{
std::unordered_set<_RefType *> m_refs;
unsigned s_added, s_removed;
unsigned m_added, m_removed;
std::mutex m_mutex;
~_RefCountLeakCheck()
{
std::lock_guard<std::mutex> lock(m_mutex);
OutputDebugString(plFormat("Refs tracked: {} created, {} destroyed\n",
s_added, s_removed).c_str());
m_added, m_removed).c_str());
if (m_refs.empty())
return;
@ -86,14 +90,16 @@ struct _RefCountLeakCheck
static void add(_RefType *node)
{
_RefCountLeakCheck<_RefType> *p = _instance();
++p->s_added;
std::lock_guard<std::mutex> lock(p->m_mutex);
++p->m_added;
p->m_refs.insert(node);
}
static void del(_RefType *node)
{
_RefCountLeakCheck<_RefType> *p = _instance();
++p->s_removed;
std::lock_guard<std::mutex> lock(p->m_mutex);
++p->m_removed;
p->m_refs.erase(node);
}
};

View File

@ -104,7 +104,7 @@ struct RelVaultNodeLink : THashKeyVal<unsigned> {
struct IRelVaultNode {
hsRef<RelVaultNode> node;
RelVaultNode * node; // MUST be a weak ref!
HASHTABLEDECL(
RelVaultNodeLink,