From daae305bf77a84cb7446096ae31d61084362fe49 Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Wed, 20 Apr 2016 23:50:43 +0200 Subject: [PATCH] fix memory leak. --- src/pthread/once.cpp | 3 +++ src/pthread/thread.cpp | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pthread/once.cpp b/src/pthread/once.cpp index 5deb4aed..d73acb70 100644 --- a/src/pthread/once.cpp +++ b/src/pthread/once.cpp @@ -53,6 +53,9 @@ namespace boost { if(memcmp(&epoch_tss_key_flag, &pthread_once_init_value, sizeof(pthread_once_t))) { + void* data = (void*)pthread_getspecific(epoch_tss_key); + if (data) + delete_epoch_tss_data(data); pthread_key_delete(epoch_tss_key); } } diff --git a/src/pthread/thread.cpp b/src/pthread/thread.cpp index 0fb76f6b..d40ac0c6 100644 --- a/src/pthread/thread.cpp +++ b/src/pthread/thread.cpp @@ -126,7 +126,9 @@ namespace boost const boost::once_flag uninitialized = BOOST_ONCE_INIT; if (memcmp(¤t_thread_tls_init_flag, &uninitialized, sizeof(boost::once_flag))) { - tls_destructor(pthread_getspecific(current_thread_tls_key)); + boost::detail::thread_data_base* data = (boost::detail::thread_data_base*)pthread_getspecific(current_thread_tls_key); + if (data) + tls_destructor(data); pthread_key_delete(current_thread_tls_key); } }