[Bug gdb/29311] [gdb] ThreadSanitizer: data race (/lib64/libtsan.so.2+0x4c5e2) in free

vries at gcc dot gnu.org sourceware-bugzilla@sourceware.org
Wed Jul 13 10:58:33 GMT 2022


https://sourceware.org/bugzilla/show_bug.cgi?id=29311

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #3)
> (In reply to Tom de Vries from comment #2)
> > So, is this a problem with 
> order of destroying things?
> 
> First the threads need to be destroyed, before objects that may have been
> used by those threads?

Hmm, in a way it could be.

There's a static vector, which is written by the main thread at initialization
time, then read by various threads, and destroyed upon exit by the main thread.

We don't wait on pending tasks before exit, so some of those could still be
running and accessing the vector, or rather, what it points to.

This stops us from xfreeing the strings contained in the vector:
...
diff --git a/gdb/charset.c b/gdb/charset.c
index 74f742e0aa7..e9d28fcb1b1 100644
--- a/gdb/charset.c
+++ b/gdb/charset.c
@@ -694,7 +694,7 @@ struct charset_vector
 {
   ~charset_vector ()
   {
-    clear ();
+    charsets.clear ();
   }

   void clear ()
...
and that fixes the race condition from comment 2.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Gdb-prs mailing list