From patchwork Mon Jan 9 23:40:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 41227 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2441654wrt; Mon, 9 Jan 2023 15:40:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXuUcbgDqmF6wyMTzj+kSqYzq2E3Z05Nmjly0FqamxzF50pxtzrx8rWkurPaNfM1ZnnjTiuo X-Received: by 2002:a05:6402:320c:b0:499:b3db:6aa3 with SMTP id g12-20020a056402320c00b00499b3db6aa3mr5376414eda.1.1673307622234; Mon, 09 Jan 2023 15:40:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673307622; cv=none; d=google.com; s=arc-20160816; b=dD+8x9zrCMm8+6XVl+yykD2iX270PYs+apLKqo0nPVIsDVMLJrUjZNIeaKbncQ3dX3 Q8UyyB/xenegEmP/GAGuAyxcvH2n4S0BvtTqQsjyW5/Zb15deAnZPulSSa4bTAaLLKTY XaisxLwRZ6NBRSZR8+om3iyL7/2RWcKifx6yppxBySj3yKMGP1aOsz5SwNFTDlTrMag1 9DgUbmmKPP7a9oFOYV2kiRgkGDbpBus264+yL/mgxpZzNfuCIB7eNmXQuD5sznaJB8XF W26KVgq32DnGNa2ul7GdDsffiBsBAOZouxv3VSEMWwgLBteMUROepXP8Jfnz+49vO3SG KHBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Y2g+oTa0KDVKpK8C/XsLbNHsKTfzcpBvbTk9bOQ1QtY=; b=UFd8fS06S5sygkEKOQSxNG028zFLSTZAlYeZ3XPHqlxlzpHW59XUUbQID1vGjUZSqe vPJRv89tP6bvHfpjpxbebzciLVB4U1U0mzmLGPVIrbAj3tsCMXmcf5lpkXhJMK2KeqNO PQhXZllD7ap/Jvs2ZI1nXU82pr7BwroOu8yHgziOX35hNx4skx/qknOVBHdQRvNjZuU+ mTQyt/ksy2dm3abbm8PZ79BGndnQBB/+Jo5LLV+kBono7dTbLmqL8uRDxRWaKGuFVl64 9gVMAWOIakamhzboZXg4l3+gUyNLksUQVPlpbO/MAEiJTFixBvyUfFKDpuK8eLbqtYJ5 JQKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=A8KYIT4L; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i9-20020a05640242c900b0048ee2e45defsi13186834edc.288.2023.01.09.15.40.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 15:40:22 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=A8KYIT4L; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 09C4F3858002 for ; Mon, 9 Jan 2023 23:40:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09C4F3858002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673307617; bh=Y2g+oTa0KDVKpK8C/XsLbNHsKTfzcpBvbTk9bOQ1QtY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=A8KYIT4Lswsj5g9h6paR7RXj9iAI3UUTdjUwydd25e7Pf3XMu6tM7tMunX/uioPzv 8V068BD5okfxnUtqDcDkItWnLsIW2o0YFm/OnNnA4YjCEVF4ECtSCTnttaLckXdfna ZKp5KJbVegD0LU6lphWMKokyjy4a2NPhrkJe6oMk= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id 73BF538582BC for ; Mon, 9 Jan 2023 23:40:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73BF538582BC Received: by mail-pl1-x62a.google.com with SMTP id p24so11315392plw.11 for ; Mon, 09 Jan 2023 15:40:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Y2g+oTa0KDVKpK8C/XsLbNHsKTfzcpBvbTk9bOQ1QtY=; b=7P9ar0pADz7cdlRoK2/zdpBg7R7BLFpUWLourx98JT+1fKHx6UUu9bCQCmHL/AK3Cz aJimq66o4Hl5yBKorACj1QQrXjniDjsxOzXH43sIylOiUzP7Z9kn0NAhllsSzPMTFWCh 5Vokj8Vl7saBKaEcY3AO2OWguEm4OnG0WWrYhPiQ0bUKNLFEOpKPyGG9/09P288JeC9V HEv4n+bdiBO0r/eO5KWStZALu0XMl2pK5AAKkl7lZ5ytaEQb5NVSxa4FbvhNbQDMNXXI sa+2mTbnQ+JbNyLF8AJc5xSIrma+Cxv6y2hBmERZxZpBrWccZG7ZWDvyonxVNuL6G1Tf 1p3Q== X-Gm-Message-State: AFqh2kqXfSXE0EfTyzBOoMgxaRwXlmboXEhyn3BO8gDM2pTtBSn189Yl 49Oo8GnmcDCVIkMj7gjsPMctGrUzTio= X-Received: by 2002:a17:90a:cf8d:b0:227:1c1e:751b with SMTP id i13-20020a17090acf8d00b002271c1e751bmr3976191pju.32.1673307607316; Mon, 09 Jan 2023 15:40:07 -0800 (PST) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id gk19-20020a17090b119300b00218f9bd50c7sm5977962pjb.50.2023.01.09.15.40.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 15:40:06 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 555281142CDB; Tue, 10 Jan 2023 10:10:04 +1030 (ACDT) Date: Tue, 10 Jan 2023 10:10:04 +1030 To: binutils@sourceware.org Subject: Set dwarf2 stash pointer earlier Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754590213251341261?= X-GMAIL-MSGID: =?utf-8?q?1754590213251341261?= This fixes a memory leak in the vanishingly rare cases (found by fuzzers of course) when something goes wrong in the save_section_vma, htab_create_alloc or alloc_trie_leaf calls before *pinfo is written. If *pinfo is not written, _bfd_dwarf2_cleanup_debug_info won't be able to free that memory. * dwarf2.c (_bfd_dwarf2_slurp_debug_info): Save stash pointer on setting up stash. diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index f689eebbd88..bd431805d2a 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -5408,6 +5408,7 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, bfd *debug_bfd, stash = (struct dwarf2_debug *) bfd_zalloc (abfd, amt); if (! stash) return false; + *pinfo = stash; } stash->orig_bfd = abfd; stash->debug_sections = debug_sections; @@ -5433,8 +5434,6 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, bfd *debug_bfd, if (!stash->alt.trie_root) return false; - *pinfo = stash; - if (debug_bfd == NULL) debug_bfd = abfd;