From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 690413857C66; Wed, 7 Jun 2023 02:02:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 690413857C66 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb] objcopy memory leaks after errors X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: d5b46032b8a6df2d8dc004759bffb6cd7ecdbe14 X-Git-Newrev: f5c0d77088ee2878813861b5b72fa64001f1831a Message-Id: <20230607020214.690413857C66@sourceware.org> Date: Wed, 7 Jun 2023 02:02:14 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Jun 2023 02:02:14 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Df5c0d77088ee= 2878813861b5b72fa64001f1831a commit f5c0d77088ee2878813861b5b72fa64001f1831a Author: Alan Modra Date: Tue Jun 6 09:50:56 2023 +0930 objcopy memory leaks after errors =20 These aren't important at all, but tidy them in case they obscure other more important leaks. =20 * 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 *ou= tput_filename, int ofd, if (ibfd =3D=3D NULL || bfd_stat (ibfd, in_stat) !=3D 0) { bfd_nonfatal_message (input_filename, NULL, NULL, NULL); + if (ibfd !=3D NULL) + bfd_close (ibfd); status =3D 1; return; } @@ -3890,6 +3892,7 @@ copy_file (const char *input_filename, const char *ou= tput_filename, int ofd, { close (ofd); bfd_nonfatal_message (output_filename, NULL, NULL, NULL); + bfd_close (ibfd); status =3D 1; return; } @@ -3922,6 +3925,7 @@ copy_file (const char *input_filename, const char *ou= tput_filename, int ofd, { close (ofd); bfd_nonfatal_message (output_filename, NULL, NULL, NULL); + bfd_close (ibfd); status =3D 1; return; } @@ -3970,6 +3974,7 @@ copy_file (const char *input_filename, const char *ou= tput_filename, int ofd, if (core_error =3D=3D bfd_error_file_ambiguously_recognized) list_matching_formats (core_matching); =20 + bfd_close (ibfd); status =3D 1; } }