Fix wxTlsValue<> memory leaks.

Win32 API doesn't provide pthreads-like destructors, so we need to
emulate them to free per-thread allocated memory.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63653 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2010-03-08 12:21:58 +00:00
parent a765eef35f
commit 49e714e127
4 changed files with 150 additions and 30 deletions

View File

@@ -21,10 +21,10 @@ class wxTlsKey
{
public:
// ctor allocates a new key and possibly registering a destructor function
// for it (notice that using destructor function is Pthreads-specific and
// not supported in Win32 implementation)
wxTlsKey(void (*destructor)(void *) = NULL)
// for it
wxTlsKey(wxTlsDestructorFunction destructor)
{
m_destructor = destructor;
if ( pthread_key_create(&m_key, destructor) != 0 )
m_key = 0;
}
@@ -41,6 +41,10 @@ public:
// change the key value, return true if ok
bool Set(void *value)
{
void *old = Get();
if ( old )
m_destructor(old);
return pthread_setspecific(m_key, value) == 0;
}
@@ -52,6 +56,7 @@ public:
}
private:
wxTlsDestructorFunction m_destructor;
pthread_key_t m_key;
wxDECLARE_NO_COPY_CLASS(wxTlsKey);