public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@sourceware.org>
To: bfd-cvs@sourceware.org
Subject: [binutils-gdb] objcopy memory leaks after errors
Date: Wed,  7 Jun 2023 02:02:14 +0000 (GMT)	[thread overview]
Message-ID: <20230607020214.690413857C66@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f5c0d77088ee2878813861b5b72fa64001f1831a

commit f5c0d77088ee2878813861b5b72fa64001f1831a
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Jun 6 09:50:56 2023 +0930

    objcopy memory leaks after errors
    
    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:
---
 binutils/objcopy.c | 5 +++++
 1 file changed, 5 insertions(+)

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;
     }
 }

                 reply	other threads:[~2023-06-07  2:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230607020214.690413857C66@sourceware.org \
    --to=amodra@sourceware.org \
    --cc=bfd-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).