From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uZKABYq1z2J4hxIAWB0awg (envelope-from ) for ; Thu, 14 Jul 2022 02:19:54 -0400 Received: by simark.ca (Postfix, from userid 112) id 078651E5EA; Thu, 14 Jul 2022 02:19:54 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=SHW7Y1zz; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 24DA51E13B for ; Thu, 14 Jul 2022 02:19:51 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 08816385701E for ; Thu, 14 Jul 2022 06:19:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 08816385701E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1657779588; bh=/FdYuyw5/gJrNoyZoSCmNrMUqcuA36Ef6di+KMuwLJ8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=SHW7Y1zzzfMCHNDvwsxzKuKM6w+vP2LBJaIc8U1J4juvoDpmR9RTqu3nYSNvYpgr7 cOcLRXn/gyqcEpv49W9nUX1yEfI1yfIYVX3pz47eqOtaXv5ketzeLv1/V0POGAZFC5 xivyA5Ym5ki0K3qnyL1juJf6eiAz+izZh0tCuSY0= Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id B020B3858C83 for ; Thu, 14 Jul 2022 06:19:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B020B3858C83 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BFC3F349B0 for ; Thu, 14 Jul 2022 06:19:26 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id AF07513A23 for ; Thu, 14 Jul 2022 06:19:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id UsuxKW61z2K8JQAAMHmgww (envelope-from ) for ; Thu, 14 Jul 2022 06:19:26 +0000 Date: Thu, 14 Jul 2022 08:19:25 +0200 To: gdb-patches@sourceware.org Subject: [committed][gdb/symtab] Fix data race in ~charset_vector Message-ID: <20220714061923.GA543@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, When doing: ... $ gdb ./outputs/gdb.ada/char_enum_unicode/foo -batch -ex "break foo.adb:26" ... with a gdb build with -fsanitize=thread I run into a data race: ... WARNING: ThreadSanitizer: data race (pid=30917) Write of size 8 at 0x7b0400004070 by main thread: #0 free (libtsan.so.2+0x4c5e2) #1 xfree gdbsupport/gdb-xfree.h:37 (gdb+0x650f17) #2 charset_vector::clear() gdb/charset.c:703 (gdb+0x651354) #3 charset_vector::~charset_vector() gdb/charset.c:697 (gdb+0x6512d3) #4 (libtsan.so.2+0x32643) #5 captured_main_1 gdb/main.c:1310 (gdb+0xa3975a) ... The problem is that we're freeing the charset_vector elements in the destructor, which may still be used by a worker thread. Fix this by not freeing the charset_vector elements in the destructor. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29311 Committed to trunk. Thanks, - Tom [gdb/symtab] Fix data race in ~charset_vector --- gdb/charset.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gdb/charset.c b/gdb/charset.c index 74f742e0aa7..a6261fc505c 100644 --- a/gdb/charset.c +++ b/gdb/charset.c @@ -694,7 +694,13 @@ struct charset_vector { ~charset_vector () { - clear (); + /* Note that we do not call charset_vector::clear, which would also xfree + the elements. This destructor is only called after exit, at which point + those will be freed anyway on process exit, so not freeing them now is + not classified as a memory leak. OTOH, freeing them now might be + classified as a data race, because some worker thread might still be + accessing them. */ + charsets.clear (); } void clear ()