memory leak in ~wxMutex fixed
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5047 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -99,17 +99,24 @@ static bool gs_waitingForThread = FALSE;
|
|||||||
class wxMutexInternal
|
class wxMutexInternal
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HANDLE p_mutex;
|
wxMutexInternal()
|
||||||
|
{
|
||||||
|
m_mutex = ::CreateMutex(NULL, FALSE, NULL);
|
||||||
|
if ( !m_mutex )
|
||||||
|
{
|
||||||
|
wxLogSysError(_("Can not create mutex"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~wxMutexInternal() { if ( m_mutex ) CloseHandle(m_mutex); }
|
||||||
|
|
||||||
|
public:
|
||||||
|
HANDLE m_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
wxMutex::wxMutex()
|
wxMutex::wxMutex()
|
||||||
{
|
{
|
||||||
m_internal = new wxMutexInternal;
|
m_internal = new wxMutexInternal;
|
||||||
m_internal->p_mutex = CreateMutex(NULL, FALSE, NULL);
|
|
||||||
if ( !m_internal->p_mutex )
|
|
||||||
{
|
|
||||||
wxLogSysError(_("Can not create mutex."));
|
|
||||||
}
|
|
||||||
|
|
||||||
m_locked = 0;
|
m_locked = 0;
|
||||||
}
|
}
|
||||||
@@ -117,15 +124,18 @@ wxMutex::wxMutex()
|
|||||||
wxMutex::~wxMutex()
|
wxMutex::~wxMutex()
|
||||||
{
|
{
|
||||||
if ( m_locked > 0 )
|
if ( m_locked > 0 )
|
||||||
wxLogDebug(wxT("Warning: freeing a locked mutex (%d locks)."), m_locked);
|
{
|
||||||
CloseHandle(m_internal->p_mutex);
|
wxLogDebug(_T("Warning: freeing a locked mutex (%d locks)."), m_locked);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete m_internal;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMutexError wxMutex::Lock()
|
wxMutexError wxMutex::Lock()
|
||||||
{
|
{
|
||||||
DWORD ret;
|
DWORD ret;
|
||||||
|
|
||||||
ret = WaitForSingleObject(m_internal->p_mutex, INFINITE);
|
ret = WaitForSingleObject(m_internal->m_mutex, INFINITE);
|
||||||
switch ( ret )
|
switch ( ret )
|
||||||
{
|
{
|
||||||
case WAIT_ABANDONED:
|
case WAIT_ABANDONED:
|
||||||
@@ -152,7 +162,7 @@ wxMutexError wxMutex::TryLock()
|
|||||||
{
|
{
|
||||||
DWORD ret;
|
DWORD ret;
|
||||||
|
|
||||||
ret = WaitForSingleObject(m_internal->p_mutex, 0);
|
ret = WaitForSingleObject(m_internal->m_mutex, 0);
|
||||||
if (ret == WAIT_TIMEOUT || ret == WAIT_ABANDONED)
|
if (ret == WAIT_TIMEOUT || ret == WAIT_ABANDONED)
|
||||||
return wxMUTEX_BUSY;
|
return wxMUTEX_BUSY;
|
||||||
|
|
||||||
@@ -165,7 +175,7 @@ wxMutexError wxMutex::Unlock()
|
|||||||
if (m_locked > 0)
|
if (m_locked > 0)
|
||||||
m_locked--;
|
m_locked--;
|
||||||
|
|
||||||
BOOL ret = ReleaseMutex(m_internal->p_mutex);
|
BOOL ret = ReleaseMutex(m_internal->m_mutex);
|
||||||
if ( ret == 0 )
|
if ( ret == 0 )
|
||||||
{
|
{
|
||||||
wxLogSysError(_("Couldn't release a mutex"));
|
wxLogSysError(_("Couldn't release a mutex"));
|
||||||
|
Reference in New Issue
Block a user