On 02.10.2014 10:03, niXman wrote: > JonY 2014-10-02 02:11: >> On 9/28/2014 14:44, lh_mouse wrote: >>> mingw-w64-libraries/winpthread/src/spinlock.c:66 >>> int initrv = pthread_spin_init (lock, >>> PTHREAD_PROCESS_PRIVATE); >>> >>> There is no corresponding pthread_spin_destroy() for this lock, hence >>> its memory leaks. >>> >> >> Kai, ping. > > I do not see where there should be the appropriate > pthread_spin_destroy(). > > Moreover, I wrote the test that shows that no leaks when using > spinlocks: > for ( int i = 0; i < 1024*1024; ++i ) { > pthread_spinlock_t s; > pthread_spin_init(&s, PTHREAD_PROCESS_PRIVATE); > pthread_spin_lock(&s); > pthread_spin_unlock(&s); > pthread_spin_destroy(&s); > } > >
Here's a patch to fix this. It does solve the problem for the simple testcase, but i have no idea how it would behave in the wild, i didn't test it on anything else. One might notice that it is set to crash when certain things happen. I'm not sure whether these things would happen with correct real-life code. If they do, we'll have to find another way. -- O< ascii ribbon - stop html email! - www.asciiribbon.org
From 6a5533c313371a2c4d552fc42510aa29a81cc035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= <lrn1...@gmail.com> Date: Wed, 22 Apr 2015 06:34:36 +0000 Subject: [PATCH] Try to eliminate spin_keys memleak --- mingw-w64-libraries/winpthreads/src/thread.c | 35 ++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/mingw-w64-libraries/winpthreads/src/thread.c b/mingw-w64-libraries/winpthreads/src/thread.c index 5c40f12..4872601 100644 --- a/mingw-w64-libraries/winpthreads/src/thread.c +++ b/mingw-w64-libraries/winpthreads/src/thread.c @@ -374,6 +374,21 @@ free_pthread_mem (void) pthread_mutex_unlock (&mtx_pthr_locked); } +static void +replace_spin_keys (pthread_spinlock_t *old, pthread_spinlock_t new) +{ + if (old == NULL) + return; + + if (EPERM == pthread_spin_destroy (old)) + { + fprintf(stderr, "Error cleaning up spin_keys for thread %lu\n", GetCurrentThreadId ()); + abort (); + } + + *old = new; +} + /* Hook for TLS-based deregistration/registration of thread. */ static BOOL WINAPI __dyn_tls_pthread (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) @@ -415,7 +430,7 @@ __dyn_tls_pthread (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) t->h = NULL; } pthread_mutex_destroy (&t->p_clock); - t->spin_keys = new_spin_keys; + replace_spin_keys (&t->spin_keys, new_spin_keys); push_pthread_mem (t); t = NULL; TlsSetValue (_pthread_tls, t); @@ -434,14 +449,14 @@ __dyn_tls_pthread (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) CloseHandle (t->h); t->h = NULL; pthread_mutex_destroy(&t->p_clock); - t->spin_keys = new_spin_keys; + replace_spin_keys (&t->spin_keys, new_spin_keys); push_pthread_mem (t); t = NULL; TlsSetValue (_pthread_tls, t); return TRUE; } pthread_mutex_destroy(&t->p_clock); - t->spin_keys = new_spin_keys; + replace_spin_keys (&t->spin_keys, new_spin_keys); } else if (t) { @@ -449,7 +464,7 @@ __dyn_tls_pthread (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) CloseHandle (t->evStart); t->evStart = NULL; pthread_mutex_destroy (&t->p_clock); - t->spin_keys = new_spin_keys; + replace_spin_keys (&t->spin_keys, new_spin_keys); } } return TRUE; @@ -963,7 +978,7 @@ __pthread_self_lite (void) t->tid = GetCurrentThreadId(); t->evStart = CreateEvent (NULL, 1, 0, NULL); t->p_clock = PTHREAD_MUTEX_INITIALIZER; - t->spin_keys = new_spin_keys; + replace_spin_keys (&t->spin_keys, new_spin_keys); t->sched_pol = SCHED_OTHER; t->h = NULL; //GetCurrentThread(); if (!DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &t->h, 0, FALSE, DUPLICATE_SAME_ACCESS)) @@ -1521,7 +1536,7 @@ pthread_create (pthread_t *th, const pthread_attr_t *attr, void *(* func)(void * while (++redo <= 4); tv->p_clock = PTHREAD_MUTEX_INITIALIZER; - tv->spin_keys = new_spin_keys; + replace_spin_keys (&tv->spin_keys, new_spin_keys); tv->valid = LIFE_THREAD; tv->sched.sched_priority = THREAD_PRIORITY_NORMAL; tv->sched_pol = SCHED_OTHER; @@ -1559,7 +1574,7 @@ pthread_create (pthread_t *th, const pthread_attr_t *attr, void *(* func)(void * if (tv->evStart) CloseHandle (tv->evStart); pthread_mutex_destroy (&tv->p_clock); - tv->spin_keys = new_spin_keys; + replace_spin_keys (&tv->spin_keys, new_spin_keys); tv->evStart = NULL; tv->h = 0; if (th) @@ -1621,7 +1636,7 @@ pthread_join (pthread_t t, void **res) if (res) *res = tv->ret_arg; pthread_mutex_destroy (&tv->p_clock); - tv->spin_keys = new_spin_keys; + replace_spin_keys (&tv->spin_keys, new_spin_keys); push_pthread_mem (tv); return 0; @@ -1671,7 +1686,7 @@ _pthread_tryjoin (pthread_t t, void **res) if (res) *res = tv->ret_arg; pthread_mutex_destroy (&tv->p_clock); - tv->spin_keys = new_spin_keys; + replace_spin_keys (&tv->spin_keys, new_spin_keys); push_pthread_mem (tv); @@ -1714,7 +1729,7 @@ pthread_detach (pthread_t t) CloseHandle (tv->evStart); tv->evStart = NULL; pthread_mutex_destroy (&tv->p_clock); - tv->spin_keys = new_spin_keys; + replace_spin_keys (&tv->spin_keys, new_spin_keys); push_pthread_mem (tv); } } -- 1.8.5.3
0x922360B0.asc
Description: application/pgp-keys
signature.asc
Description: OpenPGP digital signature
------------------------------------------------------------------------------ BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public