From patchwork Wed Jun 7 02:00:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 104187 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3791177vqr; Tue, 6 Jun 2023 19:00:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ76GqJCyQ70t6iX2OC9qfCdNzLAto+DxxKKcIgY5mWAG6mr2D2LkVNU8a6khN5mjPzF+znc X-Received: by 2002:aa7:c7d4:0:b0:514:9df0:e3f3 with SMTP id o20-20020aa7c7d4000000b005149df0e3f3mr3591295eds.0.1686103225729; Tue, 06 Jun 2023 19:00:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686103225; cv=none; d=google.com; s=arc-20160816; b=zcfY/FwnZOOZMlqRwajBBC8JtEQMSoqa8CX5LfroVHAfc71mKOQnHfGjWURMt+IM+3 f0T6girWmMvDozsn0asG7vXLKn9eDTjquBjS0xX2pIUUFJa9zjoWlom+srmT7ZLu4DJS qM4Btmf0mnq6G3newunqb25x77NcYVZBiKeL5YCsC8NqtRck/OTxGARbUjn5/atZSy6j g5f07N1AWAktbxgPQOAbG3hpWwO+71kWT2RqgTGBxn/b3zGSz51ZAWNvKkoDfVb0LVQN lQmRK0nS9OTfq4FdiYyaNUv2dZYtXekGdnbGk3pTCTsdAGIMsgxclmXttN968IFSsACP 2koQ== 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=iiICOGvrTcny+DIVQLyMzk+4HBSSEFCHwPAL4/ijx78=; b=rQRQfZm7AeF6o6bnAyH0Guo/JuO1x8ZO1AdwyorHGDP5OxjgdM+8JTLb5dKQ4EYHmY 13k5sUuzFkJs1woCyGpn2vFeWSuAEVxWkCfgR/HGjn3brj8O53tITi6M2NTUF+nwUMSl Zj6i82BHKlFPq01ViRyRRIjHt23MZeUA5iSM41vf59gt4cQOD5gd2MlFH+GluhpbWS5V 7AlJzO9o00rVyHWkOZJhhBqz+96DjMS/dLqwXXGL17SLE9CszUOkRvgaQ44fMCIhzZRU R+HNtWR+Eiw9PoFMTAWm43NeSMSgFe1A6OlFcLDTGzSbv7Y71JsKkPhMkJOKlIAUbKQr LQcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="fM8M8Dy/"; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n13-20020aa7db4d000000b005163bfbd479si7188872edt.66.2023.06.06.19.00.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 19:00:25 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="fM8M8Dy/"; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 567483857B9B for ; Wed, 7 Jun 2023 02:00:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 567483857B9B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1686103224; bh=iiICOGvrTcny+DIVQLyMzk+4HBSSEFCHwPAL4/ijx78=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=fM8M8Dy/IQVvrPqim57z7fHBF7tD+6KXCobG4mmdet3/zUc73uc3Q5V8RKGhBo/mF G3qGnvNFRgfyguCb3SCCNthLWU5P23SlTp10oEZb6cNkPjn1KPnqWgMJX2k+/hcjvE 0eU8poKh8ZkmWZjXShXLjIAcQoE956S/URE7TxlE= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id B36B9385840D for ; Wed, 7 Jun 2023 02:00:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B36B9385840D Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-6b0d38ce700so5087893a34.2 for ; Tue, 06 Jun 2023 19:00:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686103214; x=1688695214; 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=iiICOGvrTcny+DIVQLyMzk+4HBSSEFCHwPAL4/ijx78=; b=KTCQjulErC9yWHe4HlEXEA8axNevbYawDMsXEEsMh+RkTlxkXIshDO1Wcgpp/KYc4S DqkPqRIPJwGKfWIs5DiHjYF8B2lsxq70nmUCshLmZsrU7ulnpVclyaM5jihXvbunSiSg FjWAOww98LajifY8jZJzZGny5DIetX7Hj7lFNZZ3XeIjHbMths0kPL6p+1/tb+EoQV4f yKkj4PPx8LhxOxUhG1kMmaT3Ywh7uNdd4ZRthhHQhlrcdzbZmEEJwaZ/8K/NbdLfhTox 2xa9iydyamH/SPvnYQGd74ha+1N0SLQ3R0LEt4K+EoytfA6Lr/1IkngIAJYB/y8xRsnC MZ7Q== X-Gm-Message-State: AC+VfDxtUn0/bK+C9s6UwKrfdDsJGDWDFAdtLVkWEgiItvJNH0kPrew6 EbsxcNF9TjJnUtsgEq1IpcNeDwouINA= X-Received: by 2002:a9d:6d83:0:b0:6b1:5d7d:eec0 with SMTP id x3-20020a9d6d83000000b006b15d7deec0mr4147975otp.1.1686103214167; Tue, 06 Jun 2023 19:00:14 -0700 (PDT) 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 e4-20020a170902b78400b001b03d543549sm9172125pls.72.2023.06.06.19.00.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 19:00:13 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id B2E561140175; Wed, 7 Jun 2023 11:30:10 +0930 (ACST) Date: Wed, 7 Jun 2023 11:30:10 +0930 To: binutils@sourceware.org Subject: objcopy memory leaks after errors Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3034.7 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, T_SCC_BODY_TEXT_LINE 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?1768007375742084309?= X-GMAIL-MSGID: =?utf-8?q?1768007375742084309?= These aren't important at all, but tidy them in case they obscure other more important leaks. * objcopy (copy_file): Close input bfd after errors. diff --git a/binutils/objcopy.c b/binutils/objcopy.c index ac40da87018..414007780a8 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -3821,6 +3821,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd, if (ibfd == NULL || bfd_stat (ibfd, in_stat) != 0) { bfd_nonfatal_message (input_filename, NULL, NULL, NULL); + if (ibfd != NULL) + bfd_close (ibfd); status = 1; return; } @@ -3890,6 +3892,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd, { close (ofd); bfd_nonfatal_message (output_filename, NULL, NULL, NULL); + bfd_close (ibfd); status = 1; return; } @@ -3922,6 +3925,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd, { close (ofd); bfd_nonfatal_message (output_filename, NULL, NULL, NULL); + bfd_close (ibfd); status = 1; return; } @@ -3970,6 +3974,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd, if (core_error == bfd_error_file_ambiguously_recognized) list_matching_formats (core_matching); + bfd_close (ibfd); status = 1; } }