From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 53A3A3858C39 for ; Sun, 18 Dec 2022 19:34:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 53A3A3858C39 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.com 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 6F448212AE; Sun, 18 Dec 2022 19:34:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1671392046; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=k+8ilxyg1TeLATCidlcRQFZ4AwhLl82n8LCDAAxukfs=; b=tppD9WmhWO5Y8UbAAnqcwpSlb/oGl9YEHCowIWegs6ECYk20RxNhY3sEMM7wVl6r1lpxeM szPe2TTmraETyUKkYTjFI98yxQCmzxKbu3+dB0EcxhCV2BIdSWEoAev4/mTCBhvA6yqGG/ vDi7tasJBEBYEkjzFZH62EIVTlLDL5w= 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 5C1561348E; Sun, 18 Dec 2022 19:34:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id AeSiFS5rn2ObdAAAMHmgww (envelope-from ); Sun, 18 Dec 2022 19:34:06 +0000 From: Petr Pavlu To: libabigail@sourceware.org Cc: Petr Pavlu Subject: [PATCH] Fix de-initialization of elf::reader::priv Date: Sun, 18 Dec 2022 20:33:40 +0100 Message-Id: <20221218193340.30426-1-petr.pavlu@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Add a destructor for elf::reader::priv which releases any allocated alt DWARF data and fix the initialize() method to fully reset the object. The latter fixes a crash observed when handling multiple files. For instance, when reading the Linux kernel tree, load_vmlinux_corpus() processes vmlinux and all modules. Member dwarf_handle was never reset after setting it for the first file which could later result in use of invalid DWARF data in dwarf::reader::build_die_parent_maps(). * src/abg-elf-reader.cc (priv::~priv): Release alt debug information. (priv::initialize): Reset all members. (priv::clear_alt_dwarf_debug_info_data): New helper function. Fixes: 7bd69830 ("Make Front Ends first class citizens") Signed-off-by: Petr Pavlu --- src/abg-elf-reader.cc | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/abg-elf-reader.cc b/src/abg-elf-reader.cc index 3b1b5803..4814a70e 100644 --- a/src/abg-elf-reader.cc +++ b/src/abg-elf-reader.cc @@ -281,6 +281,11 @@ struct reader::priv initialize(debug_info_roots); } + ~priv() + { + clear_alt_dwarf_debug_info_data(); + } + /// Reset the private data of @elf elf::reader. /// /// @param debug_info_roots the vector of new directories where to @@ -288,11 +293,23 @@ struct reader::priv void initialize(const vector& debug_info_roots) { - debug_info_root_paths = debug_info_roots; + clear_alt_dwarf_debug_info_data(); + + elf_handle = nullptr; + symtab_section = nullptr; + elf_architecture.clear(); + dt_needed.clear(); symt.reset(); + debug_info_root_paths = debug_info_roots; + offline_callbacks = {}; dwfl_handle.reset(); elf_module = nullptr; - elf_handle = nullptr; + dwarf_handle = nullptr; + alt_dwarf_handle = nullptr; + alt_dwarf_path.clear(); + alt_dwarf_fd = 0; + ctf_section = nullptr; + alt_ctf_section = nullptr; } /// Setup the necessary plumbing to open the ELF file and find all @@ -348,6 +365,23 @@ struct reader::priv return result; } + /// Clear the resources related to the alternate DWARF data. + void + clear_alt_dwarf_debug_info_data() + { + if (alt_dwarf_fd) + { + if (alt_dwarf_handle) + { + dwarf_end(alt_dwarf_handle); + alt_dwarf_handle = nullptr; + } + close(alt_dwarf_fd); + alt_dwarf_fd = 0; + } + alt_dwarf_path.clear(); + } + /// Locate the DWARF debug info in the ELF file. /// /// This also knows how to locate split debug info. -- 2.39.0