public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] objcopy memory leaks after errors
@ 2023-06-07  2:02 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-06-07  2:02 UTC (permalink / raw)
  To: bfd-cvs

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-07  2:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-07  2:02 [binutils-gdb] objcopy memory leaks after errors Alan Modra

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).