From patchwork Wed Jan 1 12:42:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 103842 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 82D393858416 for ; Wed, 1 Jan 2025 12:57:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82D393858416 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=iupJW9Nq X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 6ABE03858C56 for ; Wed, 1 Jan 2025 12:42:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6ABE03858C56 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6ABE03858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735735335; cv=none; b=GUw8nl1duMCQBKJuEkyYS6nG8pNdGfyAvpemWKHhyMEePMhE97Ibl26bQUxzeNi6SElaKkzloCx7gxo0dw3EHTW0Zj5fTG7TezERz3XTvw/LbGHe4LnwiO8m6sQmzKNkKnsjm7iKSl5cUvS3RGfD8QOX8kvYZfRrI8ThEwmZHlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735735335; c=relaxed/simple; bh=sQwKJ8QT8SOqaCEQVkgUXfscckRbKH/fh6i27m2Ynuw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=o7FPxzgEKJO766JHUn1GLKt34yPec6wA1ZQ9gBZf07AUWxO64Bcytv6Eup4wyu3w0ibjG4NsF+liiHNiIV6B/XCvT2vilPix10VSnze9FLcy1hHrz57YKpLgSHrQH4MrNwXNzpVN433B3gFDArPIxyZIVgpLSIJ42te7IEsLo8c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6ABE03858C56 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-21619108a6bso133230435ad.3 for ; Wed, 01 Jan 2025 04:42:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735735334; x=1736340134; darn=sourceware.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=UAZUx8I7JaizPC3k6BnmE+1w7PxMMXdmSdiC0VMWGvs=; b=iupJW9NqgzYS0GqC5rTGW2O74qd7myJo/Z0mVZNDbTMplu5OatISBy7RPFrkoGZCou nZ7RGtwVfy/Om0blOR24mmGHJstJhNGyIVvA6W+yhQwdgC6MAZhA+22ULWIlU0S9nuGt 288+HeTi9IOff1Diyzqz6ftxlaYb33krceN2P9bF+wX9FdH7NoDlCEnNrmZY1d3dl01v dfy8xYKnJK0HEl/H3LksFQ/hUE3voGpBxv/RjCHhAhKAw4tRDGQfW3U4P7yImxS0fNv+ L/ymyssAeawr7zcKZ3sBhNvUfRLgWJQ9kvTsnUVaSG/hmdn36wErVtetY1afQ/Q912PO /eig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735735334; x=1736340134; 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=UAZUx8I7JaizPC3k6BnmE+1w7PxMMXdmSdiC0VMWGvs=; b=WfPwhU1FPnUNYAZz/2K44rb49AUdWPe5lsW844ncNVsY8HwFN3RbxnT4WzObFReDBT nOlagCmlBtvopaaxpwMVbOuUdjhQAn0OaGEcKQTLKl5iF23l5NvTbDKsBKMAsuf8JHKC /jnyE1r4AE25sHBOeN/8WIcFsCc3oSZMS6ySuJt0paVF0EQlTQvURCzDwE4O+fdTye30 t5Yxh+EC2rI0atnH9mZarJPhAun6HI9drIq+Z/gAHHyLMSRSTTjA7CY9WMl8WtcyUQmJ 24hfZYPheMFANAEmIKCANiMyhJqRO1D1+X4Mf8n89dW6AFEsd7Z/6eih0Zpx/x+ieoPE Rv3Q== X-Gm-Message-State: AOJu0YwfVqSrtFvVJHKS7D3TrLewbsszjaip5N2f0jp3YGf6gjimsiT5 Lc6WicdJbvXBEC/05Qk0x0FqeqrUxswpPlIFLfQ4YmOMHenif9p7OLCP2A== X-Gm-Gg: ASbGncv2TtNJ+yvsnP1GJdx/KgOlxyjBAjlRPnnK0hKG5FJvpGJa7aKhzswidoYA3Je 9Fe4MwnQg4usxfXcbD15qC6g9GFag27UcExgha6Nx07CPPNSHNny6WTtAJntmiFuTjla62Ce4jZ DmnB1LqqYzjM+zKMW6ndUo/b/qdMbyy1hMCi2oQm0ZbrAuCY4bEXMRd4zQ7cEcs5HESAbziSpq1 RCHTe4VFkDTElzHBPZCj4pUZON71zpNeZfw3lOpP5exzCS2/qc4gxlytaAoIprSDRn2ybzFWRiX qqohK+x/iIiX1R/UngC3Q/6yiXk= X-Google-Smtp-Source: AGHT+IEy8ljXElZka8d/rEkegf/TplqWtCNPC72ov/h4p6HC/fppHUTlbcNElFpzw26tLmonHHv+qg== X-Received: by 2002:a17:902:e746:b0:215:44fe:163e with SMTP id d9443c01a7336-219e6e85c04mr631541745ad.1.1735735334284; Wed, 01 Jan 2025 04:42:14 -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 d9443c01a7336-219dc964a73sm209205635ad.45.2025.01.01.04.42.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jan 2025 04:42:13 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id DAFD2114260D; Wed, 1 Jan 2025 23:12:11 +1030 (ACDT) Date: Wed, 1 Jan 2025 23:12:11 +1030 From: Alan Modra To: binutils@sourceware.org Subject: gnu_debuglink related memory leak Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3032.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.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org * opncls.c (bfd_fill_in_gnu_debuglink_section): Free section contents on success too. diff --git a/bfd/opncls.c b/bfd/opncls.c index fb0bca7689a..a0b30f568d7 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -1768,7 +1768,7 @@ bfd_fill_in_gnu_debuglink_section (bfd *abfd, debuglink_size &= ~3; debuglink_size += 4; - contents = (char *) bfd_malloc (debuglink_size); + contents = bfd_malloc (debuglink_size); if (contents == NULL) { /* XXX Should we delete the section from the bfd ? */ @@ -1781,14 +1781,9 @@ bfd_fill_in_gnu_debuglink_section (bfd *abfd, bfd_put_32 (abfd, crc32, contents + crc_offset); - if (! bfd_set_section_contents (abfd, sect, contents, 0, debuglink_size)) - { - /* XXX Should we delete the section from the bfd ? */ - free (contents); - return false; - } - - return true; + bool ret = bfd_set_section_contents (abfd, sect, contents, 0, debuglink_size); + free (contents); + return ret; } /* Finds the build-id associated with @var{abfd}. If the build-id is