Fix crashes due to static_instance.

- Initialize a needed critsect in the constructor of
  UdpSocket2ManagerWindows.
- Don't return NULL when creating a static instance.

TEST=voe_auto_test on Windows.

Review URL: http://webrtc-codereview.appspot.com/324008

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1177 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
andrew@webrtc.org 2011-12-14 02:36:33 +00:00
parent 5a9c6f26ab
commit 6d609b59f3
4 changed files with 8 additions and 14 deletions

View File

@ -25,9 +25,10 @@ UdpSocket2ManagerWindows::UdpSocket2ManagerWindows()
_id(-1),
_stopped(false),
_init(false),
_pCrit(NULL),
_pCrit(CriticalSectionWrapper::CreateCriticalSection()),
_ioCompletionHandle(NULL),
_numActiveSockets(0)
_numActiveSockets(0),
_event(EventWrapper::Create())
{
_managerNumber = _numOfActiveManagers++;
@ -40,7 +41,6 @@ UdpSocket2ManagerWindows::UdpSocket2ManagerWindows()
// if a UdpSocket2ManagerWindows() created and destroyed
// without being initialized.
}
_event = EventWrapper::Create();
}
UdpSocket2ManagerWindows::~UdpSocket2ManagerWindows()
@ -87,10 +87,10 @@ UdpSocket2ManagerWindows::~UdpSocket2ManagerWindows()
WSACleanup();
}
}
if(_pCrit)
{
delete _pCrit;
}
}
if(_pCrit)
{
delete _pCrit;
}
if(_event)
{
@ -164,11 +164,6 @@ bool UdpSocket2ManagerWindows::StartWorkerThreads()
{
if(!_init)
{
_pCrit = CriticalSectionWrapper::CreateCriticalSection();
if(_pCrit == NULL)
{
return false;
}
_pCrit->Enter();
_ioCompletionHandle = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL,

View File

@ -131,7 +131,6 @@ private:
bool _init;
WebRtc_Word32 _numActiveSockets;
ListWrapper _workerThreadsList;
WebRtc_UWord32 _numOfWorkThreads;
EventWrapper* _event;
HANDLE _ioCompletionHandle;

View File

@ -138,7 +138,6 @@ static T* GetStaticInstance(CountOperation count_operation) {
delete static_cast<T*>(new_instance);
}
}
return NULL;
} else if (state == kDestroy) {
T* old_value = static_cast<T*> (InterlockedExchangePointer(
reinterpret_cast<void* volatile*>(&instance), NULL));

View File

@ -46,6 +46,7 @@
'../interface/scoped_ptr.h',
'../interface/scoped_refptr.h',
'../interface/sort.h',
'../interface/static_instance.h',
'../interface/thread_wrapper.h',
'../interface/tick_util.h',
'../interface/trace.h',