Protect access to object tracking list of the script execution context.
Some objects are created outside of the context. git-svn-id: http://yate.null.ro/svn/yate/trunk@6447 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
cd07afa11d
commit
153f5b35b9
|
@ -37,7 +37,7 @@ class JsContext : public JsObject, public ScriptMutex
|
||||||
public:
|
public:
|
||||||
inline JsContext()
|
inline JsContext()
|
||||||
: JsObject("Context",0), ScriptMutex(true,"JsContext"),
|
: JsObject("Context",0), ScriptMutex(true,"JsContext"),
|
||||||
m_trackObjs(0)
|
m_trackObjs(0), m_trackObjsMtx(false,"JsObjTrack")
|
||||||
{
|
{
|
||||||
setMutex(this);
|
setMutex(this);
|
||||||
params().addParam(new ExpFunction("isNaN"));
|
params().addParam(new ExpFunction("isNaN"));
|
||||||
|
@ -64,6 +64,7 @@ public:
|
||||||
private:
|
private:
|
||||||
GenObject* resolveTop(ObjList& stack, const String& name, GenObject* context);
|
GenObject* resolveTop(ObjList& stack, const String& name, GenObject* context);
|
||||||
HashList* m_trackObjs;
|
HashList* m_trackObjs;
|
||||||
|
Mutex m_trackObjsMtx;
|
||||||
};
|
};
|
||||||
|
|
||||||
class JsNull : public JsObject
|
class JsNull : public JsObject
|
||||||
|
@ -989,11 +990,11 @@ void JsContext::createdObj(GenObject* obj)
|
||||||
if (!m_trackObjs)
|
if (!m_trackObjs)
|
||||||
return;
|
return;
|
||||||
JsObject* jso = YOBJECT(JsObject,obj);
|
JsObject* jso = YOBJECT(JsObject,obj);
|
||||||
JsObject* me = static_cast<JsObject*>(this);
|
if (!(jso && jso != static_cast<JsObject*>(this)))
|
||||||
if (!(jso && jso != me))
|
|
||||||
return;
|
return;
|
||||||
XDebug(DebugInfo,"Adding object=%p created at line=%u(0x%08x)",jso,jso->lineNo(),jso->lineNo());
|
XDebug(DebugInfo,"Adding object=%p created at line=%u(0x%08x)",jso,jso->lineNo(),jso->lineNo());
|
||||||
ObjList* o = m_trackObjs->append(jso,String(*((uint64_t*)jso)).hash());
|
Lock l(m_trackObjsMtx);
|
||||||
|
ObjList* o = m_trackObjs->append(jso,String((uint64_t)jso).hash());
|
||||||
if (o)
|
if (o)
|
||||||
o->setDelete(false);
|
o->setDelete(false);
|
||||||
}
|
}
|
||||||
|
@ -1006,7 +1007,8 @@ void JsContext::deletedObj(GenObject* obj)
|
||||||
if (!jso)
|
if (!jso)
|
||||||
return;
|
return;
|
||||||
XDebug(DebugInfo,"Removing object=%p created at line=%u(0x%08x)",jso,jso->lineNo(),jso->lineNo());
|
XDebug(DebugInfo,"Removing object=%p created at line=%u(0x%08x)",jso,jso->lineNo(),jso->lineNo());
|
||||||
m_trackObjs->remove(jso,String(*((uint64_t*)jso)).hash(),false);
|
Lock l(m_trackObjsMtx);
|
||||||
|
m_trackObjs->remove(jso,String((uint64_t)jso).hash(),false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsContext::trackObjs(unsigned int track)
|
void JsContext::trackObjs(unsigned int track)
|
||||||
|
@ -1024,9 +1026,12 @@ ObjList* JsContext::countAllocations()
|
||||||
return 0;
|
return 0;
|
||||||
ObjList* counters = new ObjList();
|
ObjList* counters = new ObjList();
|
||||||
for (unsigned int i = 0; i < m_trackObjs->length(); i++) {
|
for (unsigned int i = 0; i < m_trackObjs->length(); i++) {
|
||||||
|
m_trackObjsMtx.lock();
|
||||||
ObjList* l = m_trackObjs->getList(i);
|
ObjList* l = m_trackObjs->getList(i);
|
||||||
if (!l)
|
if (!l) {
|
||||||
|
m_trackObjsMtx.unlock();
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
for (ObjList* n = l->skipNull(); n; n = n->skipNext()) {
|
for (ObjList* n = l->skipNull(); n; n = n->skipNext()) {
|
||||||
JsObject* jso = YOBJECT(JsObject,n->get());
|
JsObject* jso = YOBJECT(JsObject,n->get());
|
||||||
if (!jso)
|
if (!jso)
|
||||||
|
@ -1037,6 +1042,7 @@ ObjList* JsContext::countAllocations()
|
||||||
counters->insert(count = new NamedCounter(id));
|
counters->insert(count = new NamedCounter(id));
|
||||||
count->inc();
|
count->inc();
|
||||||
}
|
}
|
||||||
|
m_trackObjsMtx.unlock();
|
||||||
}
|
}
|
||||||
if (!counters->skipNull()) {
|
if (!counters->skipNull()) {
|
||||||
TelEngine::destruct(counters);
|
TelEngine::destruct(counters);
|
||||||
|
|
|
@ -1089,9 +1089,7 @@ static bool evalCtxtAllocations(String& retVal, unsigned int count, ScriptContex
|
||||||
retVal << "Script '" << scrName << "' has no associated context\r\n";
|
retVal << "Script '" << scrName << "' has no associated context\r\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Lock l(ctx->mutex());
|
|
||||||
ObjList* objCounters = ctx->countAllocations();
|
ObjList* objCounters = ctx->countAllocations();
|
||||||
l.drop();
|
|
||||||
if (!objCounters) {
|
if (!objCounters) {
|
||||||
retVal << "Script '" << scrName << "' has no active object tracking\r\n";
|
retVal << "Script '" << scrName << "' has no active object tracking\r\n";
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue