[Bug libstdc++/52604] mt allocator crashes on multi-threaded
laurent.alfonsi at st dot com
gcc-bugzilla@gcc.gnu.org
Fri Mar 16 15:32:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52604
--- Comment #1 from Laurent Aflonsi <laurent.alfonsi at st dot com> 2012-03-16 15:25:23 UTC ---
I would propose to fix as follows :
- Set the _M_Key=NULL when calling the freelist desctuctor.
- Testing the NULL Key before using it with setspecific.
see patch below :
===================================================================
--- libstdc++-v3/src/mt_allocator.cc (revision 2486)
+++ libstdc++-v3/src/mt_allocator.cc (working copy)
@@ -47,6 +47,7 @@
if (_M_thread_freelist_array)
{
__gthread_key_delete(_M_key);
+ _M_key = NULL;
::operator delete(static_cast<void*>(_M_thread_freelist_array));
}
}
@@ -639,7 +640,8 @@
}
}
- __gthread_setspecific(freelist._M_key, (void*)_M_id);
+ if (freelist._M_key)
+ __gthread_setspecific(freelist._M_key, (void*)_M_id);
}
return _M_id >= _M_options._M_max_threads ? 0 : _M_id;
}
===================================================================
Let me know what you think
Thanks very much
Laurent Alfonsi
More information about the Gcc-bugs
mailing list