* Fixed a memory leak in wxThread

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1033 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Guilhem Lavaux
1998-11-24 19:01:20 +00:00
parent 7be07660b4
commit 6773ae198f
14 changed files with 78 additions and 54 deletions

View File

@@ -79,12 +79,12 @@ void wxMutexGuiLeave()
void wxMutexGuiEnter() void wxMutexGuiEnter()
{ {
wxMainMutex.Lock(); wxMainMutex->Lock();
} }
void wxMutexGuiLeave() void wxMutexGuiLeave()
{ {
wxMainMutex.Unlock(); wxMainMutex->Unlock();
} }
#endif #endif

View File

@@ -138,7 +138,7 @@ bool wxThread::IsAlive() const
void wxThread::SetPriority(int WXUNUSED(prio)) { } void wxThread::SetPriority(int WXUNUSED(prio)) { }
int wxThread::GetPriority() const { return 0; } int wxThread::GetPriority() const { return 0; }
wxMutex wxMainMutex; // controls access to all GUI functions wxMutex *wxMainMutex; // controls access to all GUI functions
wxThread::wxThread() wxThread::wxThread()
{ {
@@ -168,13 +168,15 @@ public:
}; };
bool wxThreadModule::OnInit() { bool wxThreadModule::OnInit() {
wxMainMutex.Lock(); wxMainMutex = new wxMutex();
wxMainMutex->Lock();
return TRUE; return TRUE;
} }
void wxThreadModule::OnExit() void wxThreadModule::OnExit()
{ {
wxMainMutex.Unlock(); wxMainMutex->Unlock();
delete wxMainMutex;
} }
IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule) IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)

View File

@@ -37,7 +37,7 @@ static pthread_t p_mainid;
static wxMutex p_list_mutex; static wxMutex p_list_mutex;
static wxList p_threads_list; static wxList p_threads_list;
wxMutex wxMainMutex; // controls access to all GUI functions wxMutex *wxMainMutex; // controls access to all GUI functions
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// GUI thread manager // GUI thread manager
@@ -288,10 +288,10 @@ void *wxThread::Join()
wxYield(); wxYield();
if (do_unlock) if (do_unlock)
wxMainMutex.Unlock(); wxMainMutex->Unlock();
pthread_join(p_internal->thread_id, &status); pthread_join(p_internal->thread_id, &status);
if (do_unlock) if (do_unlock)
wxMainMutex.Lock(); wxMainMutex->Lock();
p_list_mutex.Lock(); p_list_mutex.Lock();
delete p_threads_list.Nth(p_internal->id); delete p_threads_list.Nth(p_internal->id);
@@ -377,17 +377,19 @@ class wxThreadModule : public wxModule {
DECLARE_DYNAMIC_CLASS(wxThreadModule) DECLARE_DYNAMIC_CLASS(wxThreadModule)
public: public:
virtual bool OnInit() { virtual bool OnInit() {
wxMainMutex = new wxMutex();
wxThreadGuiInit(); wxThreadGuiInit();
p_mainid = pthread_self(); p_mainid = pthread_self();
p_threads_list = wxList(wxKEY_INTEGER); p_threads_list = wxList(wxKEY_INTEGER);
wxMainMutex.Lock(); wxMainMutex->Lock();
return TRUE; return TRUE;
} }
virtual void OnExit() { virtual void OnExit() {
wxMainMutex.Unlock(); wxMainMutex->Unlock();
wxThreadGuiExit(); wxThreadGuiExit();
delete wxMainMutex;
} }
}; };

View File

@@ -34,7 +34,7 @@ enum thread_state {
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
static int p_mainid; static int p_mainid;
wxMutex wxMainMutex; wxMutex *wxMainMutex;
#include "threadgui.inc" #include "threadgui.inc"
@@ -166,10 +166,10 @@ void *wxThread::Join()
int stat; int stat;
if (do_unlock) if (do_unlock)
wxMainMutex.Unlock(); wxMainMutex->Unlock();
waitpid(p_internal->thread_id, &stat, 0); waitpid(p_internal->thread_id, &stat, 0);
if (do_unlock) if (do_unlock)
wxMainMutex.Lock(); wxMainMutex->Lock();
if (!WIFEXITED(stat) && !WIFSIGNALED(stat)) if (!WIFEXITED(stat) && !WIFSIGNALED(stat))
return 0; return 0;
p_internal->state = STATE_IDLE; p_internal->state = STATE_IDLE;
@@ -238,14 +238,16 @@ class wxThreadModule : public wxModule {
DECLARE_DYNAMIC_CLASS(wxThreadModule) DECLARE_DYNAMIC_CLASS(wxThreadModule)
public: public:
virtual bool OnInit() { virtual bool OnInit() {
wxMainMutex = new wxMutex();
wxThreadGuiInit(); wxThreadGuiInit();
p_mainid = (int)getpid(); p_mainid = (int)getpid();
wxMainMutex.Lock(); wxMainMutex->Lock();
} }
virtual void OnExit() { virtual void OnExit() {
wxMainMutex.Unlock(); wxMainMutex->Unlock();
wxThreadGuiExit(); wxThreadGuiExit();
delete wxMainMutex;
} }
}; };

View File

@@ -79,12 +79,12 @@ void wxMutexGuiLeave()
void wxMutexGuiEnter() void wxMutexGuiEnter()
{ {
wxMainMutex.Lock(); wxMainMutex->Lock();
} }
void wxMutexGuiLeave() void wxMutexGuiLeave()
{ {
wxMainMutex.Unlock(); wxMainMutex->Unlock();
} }
#endif #endif

View File

@@ -138,7 +138,7 @@ bool wxThread::IsAlive() const
void wxThread::SetPriority(int WXUNUSED(prio)) { } void wxThread::SetPriority(int WXUNUSED(prio)) { }
int wxThread::GetPriority() const { return 0; } int wxThread::GetPriority() const { return 0; }
wxMutex wxMainMutex; // controls access to all GUI functions wxMutex *wxMainMutex; // controls access to all GUI functions
wxThread::wxThread() wxThread::wxThread()
{ {
@@ -168,13 +168,15 @@ public:
}; };
bool wxThreadModule::OnInit() { bool wxThreadModule::OnInit() {
wxMainMutex.Lock(); wxMainMutex = new wxMutex();
wxMainMutex->Lock();
return TRUE; return TRUE;
} }
void wxThreadModule::OnExit() void wxThreadModule::OnExit()
{ {
wxMainMutex.Unlock(); wxMainMutex->Unlock();
delete wxMainMutex;
} }
IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule) IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)

View File

@@ -37,7 +37,7 @@ static pthread_t p_mainid;
static wxMutex p_list_mutex; static wxMutex p_list_mutex;
static wxList p_threads_list; static wxList p_threads_list;
wxMutex wxMainMutex; // controls access to all GUI functions wxMutex *wxMainMutex; // controls access to all GUI functions
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// GUI thread manager // GUI thread manager
@@ -288,10 +288,10 @@ void *wxThread::Join()
wxYield(); wxYield();
if (do_unlock) if (do_unlock)
wxMainMutex.Unlock(); wxMainMutex->Unlock();
pthread_join(p_internal->thread_id, &status); pthread_join(p_internal->thread_id, &status);
if (do_unlock) if (do_unlock)
wxMainMutex.Lock(); wxMainMutex->Lock();
p_list_mutex.Lock(); p_list_mutex.Lock();
delete p_threads_list.Nth(p_internal->id); delete p_threads_list.Nth(p_internal->id);
@@ -377,17 +377,19 @@ class wxThreadModule : public wxModule {
DECLARE_DYNAMIC_CLASS(wxThreadModule) DECLARE_DYNAMIC_CLASS(wxThreadModule)
public: public:
virtual bool OnInit() { virtual bool OnInit() {
wxMainMutex = new wxMutex();
wxThreadGuiInit(); wxThreadGuiInit();
p_mainid = pthread_self(); p_mainid = pthread_self();
p_threads_list = wxList(wxKEY_INTEGER); p_threads_list = wxList(wxKEY_INTEGER);
wxMainMutex.Lock(); wxMainMutex->Lock();
return TRUE; return TRUE;
} }
virtual void OnExit() { virtual void OnExit() {
wxMainMutex.Unlock(); wxMainMutex->Unlock();
wxThreadGuiExit(); wxThreadGuiExit();
delete wxMainMutex;
} }
}; };

View File

@@ -34,7 +34,7 @@ enum thread_state {
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
static int p_mainid; static int p_mainid;
wxMutex wxMainMutex; wxMutex *wxMainMutex;
#include "threadgui.inc" #include "threadgui.inc"
@@ -166,10 +166,10 @@ void *wxThread::Join()
int stat; int stat;
if (do_unlock) if (do_unlock)
wxMainMutex.Unlock(); wxMainMutex->Unlock();
waitpid(p_internal->thread_id, &stat, 0); waitpid(p_internal->thread_id, &stat, 0);
if (do_unlock) if (do_unlock)
wxMainMutex.Lock(); wxMainMutex->Lock();
if (!WIFEXITED(stat) && !WIFSIGNALED(stat)) if (!WIFEXITED(stat) && !WIFSIGNALED(stat))
return 0; return 0;
p_internal->state = STATE_IDLE; p_internal->state = STATE_IDLE;
@@ -238,14 +238,16 @@ class wxThreadModule : public wxModule {
DECLARE_DYNAMIC_CLASS(wxThreadModule) DECLARE_DYNAMIC_CLASS(wxThreadModule)
public: public:
virtual bool OnInit() { virtual bool OnInit() {
wxMainMutex = new wxMutex();
wxThreadGuiInit(); wxThreadGuiInit();
p_mainid = (int)getpid(); p_mainid = (int)getpid();
wxMainMutex.Lock(); wxMainMutex->Lock();
} }
virtual void OnExit() { virtual void OnExit() {
wxMainMutex.Unlock(); wxMainMutex->Unlock();
wxThreadGuiExit(); wxThreadGuiExit();
delete wxMainMutex;
} }
}; };

View File

@@ -28,7 +28,7 @@ enum thread_state {
// Static variables // Static variables
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
wxMutex wxMainMutex; // controls access to all GUI functions wxMutex *wxMainMutex; // controls access to all GUI functions
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Windows implementation // Windows implementation
@@ -243,13 +243,15 @@ class wxThreadModule : public wxModule {
public: public:
virtual bool OnInit() { virtual bool OnInit() {
/* TODO p_mainid = GetCurrentThread(); */ /* TODO p_mainid = GetCurrentThread(); */
wxMainMutex.Lock(); wxMainMutex = new wxMutex();
wxMainMutex->Lock();
return TRUE; return TRUE;
} }
// Global cleanup // Global cleanup
virtual void OnExit() { virtual void OnExit() {
wxMainMutex.Unlock(); wxMainMutex->Unlock();
delete wxMainMutex;
} }
}; };

View File

@@ -44,7 +44,7 @@ enum thread_state {
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
static HANDLE p_mainid; static HANDLE p_mainid;
wxMutex wxMainMutex; // controls access to all GUI functions wxMutex *wxMainMutex; // controls access to all GUI functions
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Windows implementation // Windows implementation
@@ -260,10 +260,10 @@ void *wxThread::Join()
return NULL; return NULL;
if (wxThread::IsMain()) if (wxThread::IsMain())
wxMainMutex.Unlock(); wxMainMutex->Unlock();
WaitForSingleObject(p_internal->thread_id, INFINITE); WaitForSingleObject(p_internal->thread_id, INFINITE);
if (wxThread::IsMain()) if (wxThread::IsMain())
wxMainMutex.Lock(); wxMainMutex->Lock();
GetExitCodeThread(p_internal->thread_id, &exit_code); GetExitCodeThread(p_internal->thread_id, &exit_code);
CloseHandle(p_internal->thread_id); CloseHandle(p_internal->thread_id);
@@ -310,14 +310,16 @@ class wxThreadModule : public wxModule {
DECLARE_DYNAMIC_CLASS(wxThreadModule) DECLARE_DYNAMIC_CLASS(wxThreadModule)
public: public:
virtual bool OnInit() { virtual bool OnInit() {
wxMainMutex = new wxMutex();
p_mainid = GetCurrentThread(); p_mainid = GetCurrentThread();
wxMainMutex.Lock(); wxMainMutex->Lock();
return TRUE; return TRUE;
} }
// Global cleanup // Global cleanup
virtual void OnExit() { virtual void OnExit() {
wxMainMutex.Unlock(); wxMainMutex->Unlock();
delete wxMainMutex;
} }
}; };

View File

@@ -143,7 +143,7 @@ bool wxThread::IsAlive() const
void wxThread::SetPriority(int WXUNUSED(prio)) { } void wxThread::SetPriority(int WXUNUSED(prio)) { }
int wxThread::GetPriority() const { return 0; } int wxThread::GetPriority() const { return 0; }
wxMutex wxMainMutex; // controls access to all GUI functions wxMutex *wxMainMutex; // controls access to all GUI functions
wxThread::wxThread() wxThread::wxThread()
{ {
@@ -173,13 +173,15 @@ public:
}; };
bool wxThreadModule::OnInit() { bool wxThreadModule::OnInit() {
wxMainMutex.Lock(); wxMainMutex = new wxMutex();
wxMainMutex->Lock();
return TRUE; return TRUE;
} }
void wxThreadModule::OnExit() void wxThreadModule::OnExit()
{ {
wxMainMutex.Unlock(); wxMainMutex->Unlock();
delete wxMainMutex;
} }
IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule) IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)

View File

@@ -37,7 +37,7 @@ static pthread_t p_mainid;
static wxMutex p_list_mutex; static wxMutex p_list_mutex;
static wxList p_threads_list; static wxList p_threads_list;
wxMutex wxMainMutex; // controls access to all GUI functions wxMutex *wxMainMutex; // controls access to all GUI functions
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// GUI thread manager // GUI thread manager
@@ -288,10 +288,10 @@ void *wxThread::Join()
wxYield(); wxYield();
if (do_unlock) if (do_unlock)
wxMainMutex.Unlock(); wxMainMutex->Unlock();
pthread_join(p_internal->thread_id, &status); pthread_join(p_internal->thread_id, &status);
if (do_unlock) if (do_unlock)
wxMainMutex.Lock(); wxMainMutex->Lock();
p_list_mutex.Lock(); p_list_mutex.Lock();
delete p_threads_list.Nth(p_internal->id); delete p_threads_list.Nth(p_internal->id);
@@ -377,17 +377,19 @@ class wxThreadModule : public wxModule {
DECLARE_DYNAMIC_CLASS(wxThreadModule) DECLARE_DYNAMIC_CLASS(wxThreadModule)
public: public:
virtual bool OnInit() { virtual bool OnInit() {
wxMainMutex = new wxMutex();
wxThreadGuiInit(); wxThreadGuiInit();
p_mainid = pthread_self(); p_mainid = pthread_self();
p_threads_list = wxList(wxKEY_INTEGER); p_threads_list = wxList(wxKEY_INTEGER);
wxMainMutex.Lock(); wxMainMutex->Lock();
return TRUE; return TRUE;
} }
virtual void OnExit() { virtual void OnExit() {
wxMainMutex.Unlock(); wxMainMutex->Unlock();
wxThreadGuiExit(); wxThreadGuiExit();
delete wxMainMutex;
} }
}; };

View File

@@ -34,7 +34,7 @@ enum thread_state {
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
static int p_mainid; static int p_mainid;
wxMutex wxMainMutex; wxMutex *wxMainMutex;
#include "threadgui.inc" #include "threadgui.inc"
@@ -166,10 +166,10 @@ void *wxThread::Join()
int stat; int stat;
if (do_unlock) if (do_unlock)
wxMainMutex.Unlock(); wxMainMutex->Unlock();
waitpid(p_internal->thread_id, &stat, 0); waitpid(p_internal->thread_id, &stat, 0);
if (do_unlock) if (do_unlock)
wxMainMutex.Lock(); wxMainMutex->Lock();
if (!WIFEXITED(stat) && !WIFSIGNALED(stat)) if (!WIFEXITED(stat) && !WIFSIGNALED(stat))
return 0; return 0;
p_internal->state = STATE_IDLE; p_internal->state = STATE_IDLE;
@@ -238,14 +238,16 @@ class wxThreadModule : public wxModule {
DECLARE_DYNAMIC_CLASS(wxThreadModule) DECLARE_DYNAMIC_CLASS(wxThreadModule)
public: public:
virtual bool OnInit() { virtual bool OnInit() {
wxMainMutex = new wxMutex();
wxThreadGuiInit(); wxThreadGuiInit();
p_mainid = (int)getpid(); p_mainid = (int)getpid();
wxMainMutex.Lock(); wxMainMutex->Lock();
} }
virtual void OnExit() { virtual void OnExit() {
wxMainMutex.Unlock(); wxMainMutex->Unlock();
wxThreadGuiExit(); wxThreadGuiExit();
delete wxMainMutex;
} }
}; };

View File

@@ -28,7 +28,7 @@ enum thread_state {
// Static variables // Static variables
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
wxMutex wxMainMutex; // controls access to all GUI functions wxMutex *wxMainMutex; // controls access to all GUI functions
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Windows implementation // Windows implementation
@@ -243,13 +243,15 @@ class wxThreadModule : public wxModule {
public: public:
virtual bool OnInit() { virtual bool OnInit() {
/* TODO p_mainid = GetCurrentThread(); */ /* TODO p_mainid = GetCurrentThread(); */
wxMainMutex.Lock(); wxMainMutex = new wxMutex();
wxMainMutex->Lock();
return TRUE; return TRUE;
} }
// Global cleanup // Global cleanup
virtual void OnExit() { virtual void OnExit() {
wxMainMutex.Unlock(); wxMainMutex->Unlock();
delete wxMainMutex;
} }
}; };