From 6773ae198f4ff542231d85b4df7283af143d82eb Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Tue, 24 Nov 1998 19:01:20 +0000 Subject: [PATCH] * Fixed a memory leak in wxThread git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1033 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/threadgui.inc | 4 ++-- src/gtk/threadno.cpp | 8 +++++--- src/gtk/threadpsx.cpp | 12 +++++++----- src/gtk/threadsgi.cpp | 12 +++++++----- src/gtk1/threadgui.inc | 4 ++-- src/gtk1/threadno.cpp | 8 +++++--- src/gtk1/threadpsx.cpp | 12 +++++++----- src/gtk1/threadsgi.cpp | 12 +++++++----- src/motif/thread.cpp | 8 +++++--- src/msw/thread.cpp | 12 +++++++----- src/qt/threadno.cpp | 8 +++++--- src/qt/threadpsx.cpp | 12 +++++++----- src/qt/threadsgi.cpp | 12 +++++++----- src/stubs/thread.cpp | 8 +++++--- 14 files changed, 78 insertions(+), 54 deletions(-) diff --git a/src/gtk/threadgui.inc b/src/gtk/threadgui.inc index baa8fe8b76..46073d4e0b 100644 --- a/src/gtk/threadgui.inc +++ b/src/gtk/threadgui.inc @@ -79,12 +79,12 @@ void wxMutexGuiLeave() void wxMutexGuiEnter() { - wxMainMutex.Lock(); + wxMainMutex->Lock(); } void wxMutexGuiLeave() { - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); } #endif diff --git a/src/gtk/threadno.cpp b/src/gtk/threadno.cpp index 3a1f3460c7..375d2ac6a7 100644 --- a/src/gtk/threadno.cpp +++ b/src/gtk/threadno.cpp @@ -138,7 +138,7 @@ bool wxThread::IsAlive() const void wxThread::SetPriority(int WXUNUSED(prio)) { } int wxThread::GetPriority() const { return 0; } -wxMutex wxMainMutex; // controls access to all GUI functions +wxMutex *wxMainMutex; // controls access to all GUI functions wxThread::wxThread() { @@ -168,13 +168,15 @@ public: }; bool wxThreadModule::OnInit() { - wxMainMutex.Lock(); + wxMainMutex = new wxMutex(); + wxMainMutex->Lock(); return TRUE; } void wxThreadModule::OnExit() { - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); + delete wxMainMutex; } IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule) diff --git a/src/gtk/threadpsx.cpp b/src/gtk/threadpsx.cpp index 9623b91c30..2d4912c05a 100644 --- a/src/gtk/threadpsx.cpp +++ b/src/gtk/threadpsx.cpp @@ -37,7 +37,7 @@ static pthread_t p_mainid; static wxMutex p_list_mutex; static wxList p_threads_list; -wxMutex wxMainMutex; // controls access to all GUI functions +wxMutex *wxMainMutex; // controls access to all GUI functions ///////////////////////////////////////////////////////////////////////////// // GUI thread manager @@ -288,10 +288,10 @@ void *wxThread::Join() wxYield(); if (do_unlock) - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); pthread_join(p_internal->thread_id, &status); if (do_unlock) - wxMainMutex.Lock(); + wxMainMutex->Lock(); p_list_mutex.Lock(); delete p_threads_list.Nth(p_internal->id); @@ -377,17 +377,19 @@ class wxThreadModule : public wxModule { DECLARE_DYNAMIC_CLASS(wxThreadModule) public: virtual bool OnInit() { + wxMainMutex = new wxMutex(); wxThreadGuiInit(); p_mainid = pthread_self(); p_threads_list = wxList(wxKEY_INTEGER); - wxMainMutex.Lock(); + wxMainMutex->Lock(); return TRUE; } virtual void OnExit() { - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); wxThreadGuiExit(); + delete wxMainMutex; } }; diff --git a/src/gtk/threadsgi.cpp b/src/gtk/threadsgi.cpp index 3503e79616..66b6b0da7b 100644 --- a/src/gtk/threadsgi.cpp +++ b/src/gtk/threadsgi.cpp @@ -34,7 +34,7 @@ enum thread_state { ///////////////////////////////////////////////////////////////////////////// static int p_mainid; -wxMutex wxMainMutex; +wxMutex *wxMainMutex; #include "threadgui.inc" @@ -166,10 +166,10 @@ void *wxThread::Join() int stat; if (do_unlock) - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); waitpid(p_internal->thread_id, &stat, 0); if (do_unlock) - wxMainMutex.Lock(); + wxMainMutex->Lock(); if (!WIFEXITED(stat) && !WIFSIGNALED(stat)) return 0; p_internal->state = STATE_IDLE; @@ -238,14 +238,16 @@ class wxThreadModule : public wxModule { DECLARE_DYNAMIC_CLASS(wxThreadModule) public: virtual bool OnInit() { + wxMainMutex = new wxMutex(); wxThreadGuiInit(); p_mainid = (int)getpid(); - wxMainMutex.Lock(); + wxMainMutex->Lock(); } virtual void OnExit() { - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); wxThreadGuiExit(); + delete wxMainMutex; } }; diff --git a/src/gtk1/threadgui.inc b/src/gtk1/threadgui.inc index baa8fe8b76..46073d4e0b 100644 --- a/src/gtk1/threadgui.inc +++ b/src/gtk1/threadgui.inc @@ -79,12 +79,12 @@ void wxMutexGuiLeave() void wxMutexGuiEnter() { - wxMainMutex.Lock(); + wxMainMutex->Lock(); } void wxMutexGuiLeave() { - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); } #endif diff --git a/src/gtk1/threadno.cpp b/src/gtk1/threadno.cpp index 3a1f3460c7..375d2ac6a7 100644 --- a/src/gtk1/threadno.cpp +++ b/src/gtk1/threadno.cpp @@ -138,7 +138,7 @@ bool wxThread::IsAlive() const void wxThread::SetPriority(int WXUNUSED(prio)) { } int wxThread::GetPriority() const { return 0; } -wxMutex wxMainMutex; // controls access to all GUI functions +wxMutex *wxMainMutex; // controls access to all GUI functions wxThread::wxThread() { @@ -168,13 +168,15 @@ public: }; bool wxThreadModule::OnInit() { - wxMainMutex.Lock(); + wxMainMutex = new wxMutex(); + wxMainMutex->Lock(); return TRUE; } void wxThreadModule::OnExit() { - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); + delete wxMainMutex; } IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule) diff --git a/src/gtk1/threadpsx.cpp b/src/gtk1/threadpsx.cpp index 9623b91c30..2d4912c05a 100644 --- a/src/gtk1/threadpsx.cpp +++ b/src/gtk1/threadpsx.cpp @@ -37,7 +37,7 @@ static pthread_t p_mainid; static wxMutex p_list_mutex; static wxList p_threads_list; -wxMutex wxMainMutex; // controls access to all GUI functions +wxMutex *wxMainMutex; // controls access to all GUI functions ///////////////////////////////////////////////////////////////////////////// // GUI thread manager @@ -288,10 +288,10 @@ void *wxThread::Join() wxYield(); if (do_unlock) - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); pthread_join(p_internal->thread_id, &status); if (do_unlock) - wxMainMutex.Lock(); + wxMainMutex->Lock(); p_list_mutex.Lock(); delete p_threads_list.Nth(p_internal->id); @@ -377,17 +377,19 @@ class wxThreadModule : public wxModule { DECLARE_DYNAMIC_CLASS(wxThreadModule) public: virtual bool OnInit() { + wxMainMutex = new wxMutex(); wxThreadGuiInit(); p_mainid = pthread_self(); p_threads_list = wxList(wxKEY_INTEGER); - wxMainMutex.Lock(); + wxMainMutex->Lock(); return TRUE; } virtual void OnExit() { - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); wxThreadGuiExit(); + delete wxMainMutex; } }; diff --git a/src/gtk1/threadsgi.cpp b/src/gtk1/threadsgi.cpp index 3503e79616..66b6b0da7b 100644 --- a/src/gtk1/threadsgi.cpp +++ b/src/gtk1/threadsgi.cpp @@ -34,7 +34,7 @@ enum thread_state { ///////////////////////////////////////////////////////////////////////////// static int p_mainid; -wxMutex wxMainMutex; +wxMutex *wxMainMutex; #include "threadgui.inc" @@ -166,10 +166,10 @@ void *wxThread::Join() int stat; if (do_unlock) - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); waitpid(p_internal->thread_id, &stat, 0); if (do_unlock) - wxMainMutex.Lock(); + wxMainMutex->Lock(); if (!WIFEXITED(stat) && !WIFSIGNALED(stat)) return 0; p_internal->state = STATE_IDLE; @@ -238,14 +238,16 @@ class wxThreadModule : public wxModule { DECLARE_DYNAMIC_CLASS(wxThreadModule) public: virtual bool OnInit() { + wxMainMutex = new wxMutex(); wxThreadGuiInit(); p_mainid = (int)getpid(); - wxMainMutex.Lock(); + wxMainMutex->Lock(); } virtual void OnExit() { - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); wxThreadGuiExit(); + delete wxMainMutex; } }; diff --git a/src/motif/thread.cpp b/src/motif/thread.cpp index c197787003..ca3833153a 100644 --- a/src/motif/thread.cpp +++ b/src/motif/thread.cpp @@ -28,7 +28,7 @@ enum thread_state { // Static variables ///////////////////////////////////////////////////////////////////////////// -wxMutex wxMainMutex; // controls access to all GUI functions +wxMutex *wxMainMutex; // controls access to all GUI functions ///////////////////////////////////////////////////////////////////////////// // Windows implementation @@ -243,13 +243,15 @@ class wxThreadModule : public wxModule { public: virtual bool OnInit() { /* TODO p_mainid = GetCurrentThread(); */ - wxMainMutex.Lock(); + wxMainMutex = new wxMutex(); + wxMainMutex->Lock(); return TRUE; } // Global cleanup virtual void OnExit() { - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); + delete wxMainMutex; } }; diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index 176d1e4cc1..a592fbf29e 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -44,7 +44,7 @@ enum thread_state { ///////////////////////////////////////////////////////////////////////////// static HANDLE p_mainid; -wxMutex wxMainMutex; // controls access to all GUI functions +wxMutex *wxMainMutex; // controls access to all GUI functions ///////////////////////////////////////////////////////////////////////////// // Windows implementation @@ -260,10 +260,10 @@ void *wxThread::Join() return NULL; if (wxThread::IsMain()) - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); WaitForSingleObject(p_internal->thread_id, INFINITE); if (wxThread::IsMain()) - wxMainMutex.Lock(); + wxMainMutex->Lock(); GetExitCodeThread(p_internal->thread_id, &exit_code); CloseHandle(p_internal->thread_id); @@ -310,14 +310,16 @@ class wxThreadModule : public wxModule { DECLARE_DYNAMIC_CLASS(wxThreadModule) public: virtual bool OnInit() { + wxMainMutex = new wxMutex(); p_mainid = GetCurrentThread(); - wxMainMutex.Lock(); + wxMainMutex->Lock(); return TRUE; } // Global cleanup virtual void OnExit() { - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); + delete wxMainMutex; } }; diff --git a/src/qt/threadno.cpp b/src/qt/threadno.cpp index b0db0f426a..8cf94d1e06 100644 --- a/src/qt/threadno.cpp +++ b/src/qt/threadno.cpp @@ -143,7 +143,7 @@ bool wxThread::IsAlive() const void wxThread::SetPriority(int WXUNUSED(prio)) { } int wxThread::GetPriority() const { return 0; } -wxMutex wxMainMutex; // controls access to all GUI functions +wxMutex *wxMainMutex; // controls access to all GUI functions wxThread::wxThread() { @@ -173,13 +173,15 @@ public: }; bool wxThreadModule::OnInit() { - wxMainMutex.Lock(); + wxMainMutex = new wxMutex(); + wxMainMutex->Lock(); return TRUE; } void wxThreadModule::OnExit() { - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); + delete wxMainMutex; } IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule) diff --git a/src/qt/threadpsx.cpp b/src/qt/threadpsx.cpp index 9623b91c30..2d4912c05a 100644 --- a/src/qt/threadpsx.cpp +++ b/src/qt/threadpsx.cpp @@ -37,7 +37,7 @@ static pthread_t p_mainid; static wxMutex p_list_mutex; static wxList p_threads_list; -wxMutex wxMainMutex; // controls access to all GUI functions +wxMutex *wxMainMutex; // controls access to all GUI functions ///////////////////////////////////////////////////////////////////////////// // GUI thread manager @@ -288,10 +288,10 @@ void *wxThread::Join() wxYield(); if (do_unlock) - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); pthread_join(p_internal->thread_id, &status); if (do_unlock) - wxMainMutex.Lock(); + wxMainMutex->Lock(); p_list_mutex.Lock(); delete p_threads_list.Nth(p_internal->id); @@ -377,17 +377,19 @@ class wxThreadModule : public wxModule { DECLARE_DYNAMIC_CLASS(wxThreadModule) public: virtual bool OnInit() { + wxMainMutex = new wxMutex(); wxThreadGuiInit(); p_mainid = pthread_self(); p_threads_list = wxList(wxKEY_INTEGER); - wxMainMutex.Lock(); + wxMainMutex->Lock(); return TRUE; } virtual void OnExit() { - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); wxThreadGuiExit(); + delete wxMainMutex; } }; diff --git a/src/qt/threadsgi.cpp b/src/qt/threadsgi.cpp index 3503e79616..66b6b0da7b 100644 --- a/src/qt/threadsgi.cpp +++ b/src/qt/threadsgi.cpp @@ -34,7 +34,7 @@ enum thread_state { ///////////////////////////////////////////////////////////////////////////// static int p_mainid; -wxMutex wxMainMutex; +wxMutex *wxMainMutex; #include "threadgui.inc" @@ -166,10 +166,10 @@ void *wxThread::Join() int stat; if (do_unlock) - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); waitpid(p_internal->thread_id, &stat, 0); if (do_unlock) - wxMainMutex.Lock(); + wxMainMutex->Lock(); if (!WIFEXITED(stat) && !WIFSIGNALED(stat)) return 0; p_internal->state = STATE_IDLE; @@ -238,14 +238,16 @@ class wxThreadModule : public wxModule { DECLARE_DYNAMIC_CLASS(wxThreadModule) public: virtual bool OnInit() { + wxMainMutex = new wxMutex(); wxThreadGuiInit(); p_mainid = (int)getpid(); - wxMainMutex.Lock(); + wxMainMutex->Lock(); } virtual void OnExit() { - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); wxThreadGuiExit(); + delete wxMainMutex; } }; diff --git a/src/stubs/thread.cpp b/src/stubs/thread.cpp index c197787003..ca3833153a 100644 --- a/src/stubs/thread.cpp +++ b/src/stubs/thread.cpp @@ -28,7 +28,7 @@ enum thread_state { // Static variables ///////////////////////////////////////////////////////////////////////////// -wxMutex wxMainMutex; // controls access to all GUI functions +wxMutex *wxMainMutex; // controls access to all GUI functions ///////////////////////////////////////////////////////////////////////////// // Windows implementation @@ -243,13 +243,15 @@ class wxThreadModule : public wxModule { public: virtual bool OnInit() { /* TODO p_mainid = GetCurrentThread(); */ - wxMainMutex.Lock(); + wxMainMutex = new wxMutex(); + wxMainMutex->Lock(); return TRUE; } // Global cleanup virtual void OnExit() { - wxMainMutex.Unlock(); + wxMainMutex->Unlock(); + delete wxMainMutex; } }; -- 2.47.2