From 98333b7dcfff6ab5899f58176cd55dd53b0b3422 Mon Sep 17 00:00:00 2001 From: Anthony Williams Date: Tue, 9 Nov 2010 12:54:23 +0000 Subject: [PATCH] fix for issue #4736 --- avoid setting tls data after the key has been destroyed [SVN r66471] --- src/win32/thread.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/win32/thread.cpp b/src/win32/thread.cpp index 756ce6dd..e6bf20a4 100644 --- a/src/win32/thread.cpp +++ b/src/win32/thread.cpp @@ -56,7 +56,8 @@ namespace boost void set_current_thread_data(detail::thread_data_base* new_data) { boost::call_once(current_thread_tls_init_flag,create_current_thread_tls_key); - BOOST_VERIFY(TlsSetValue(current_thread_tls_key,new_data)); + if(current_thread_tls_key) + BOOST_VERIFY(TlsSetValue(current_thread_tls_key,new_data)); } #ifdef BOOST_NO_THREADEX @@ -226,6 +227,10 @@ namespace boost detail::thread_data_base* get_or_make_current_thread_data() { + if(!current_thread_tls_key) + { + throw thread_resource_error(); + } detail::thread_data_base* current_thread_data(get_current_thread_data()); if(!current_thread_data) { @@ -540,8 +545,8 @@ namespace boost { detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data()); thread_exit_callback_node* const new_node= - heap_new(func, - current_thread_data->thread_exit_callbacks); + heap_new( + func,current_thread_data->thread_exit_callbacks); current_thread_data->thread_exit_callbacks=new_node; } @@ -583,10 +588,11 @@ namespace boost current_node->func=func; current_node->value=tss_data; } - else + else if(func && tss_data) { detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data()); - tss_data_node* const new_node=heap_new(key,func,tss_data,current_thread_data->tss_data); + tss_data_node* const new_node= + heap_new(key,func,tss_data,current_thread_data->tss_data); current_thread_data->tss_data=new_node; } }