Hold the ChanAssistList mutex between the list search and insertion of new assist in list.

This prevents race conditions between chan.startup and call.execute that could create two assist instances for the same channel.


git-svn-id: http://voip.null.ro/svn/yate@2853 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2009-09-23 14:00:38 +00:00
parent 0020599c05
commit 3b553da8b1
1 changed files with 8 additions and 6 deletions

View File

@ -31,27 +31,27 @@ bool ChanAssistList::received(Message& msg, int id)
String* chanId = msg.getParam("id");
if (!chanId || chanId->null())
return (id < Private) && Module::received(msg,id);
lock();
Lock mylock(this);
RefPointer <ChanAssist> ca = find(*chanId);
unlock();
switch (id) {
case Startup:
if (ca) {
Debug(this,DebugNote,"Channel '%s' already assisted!",chanId->c_str());
mylock.drop();
ca->msgStartup(msg);
return false;
}
ca = create(msg,*chanId);
if (ca) {
lock();
m_calls.append(ca);
unlock();
mylock.drop();
ca->msgStartup(msg);
}
return false;
case Hangup:
if (ca) {
removeAssist(ca);
mylock.drop();
ca->msgHangup(msg);
ca->deref();
ca = 0;
@ -59,21 +59,23 @@ bool ChanAssistList::received(Message& msg, int id)
return false;
case Execute:
if (ca) {
mylock.drop();
ca->msgExecute(msg);
return false;
}
ca = create(msg,*chanId);
if (ca) {
lock();
m_calls.append(ca);
unlock();
mylock.drop();
ca->msgStartup(msg);
ca->msgExecute(msg);
}
return false;
case Disconnected:
mylock.drop();
return ca && ca->msgDisconnect(msg,msg.getValue("reason"));
default:
mylock.drop();
if (ca)
return received(msg,id,ca);
return (id < Private) && Module::received(msg,id);