]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
ar: Always close newfd in do_oper_insert.
authorMark Wielaard <mark@klomp.org>
Sat, 3 Apr 2021 17:20:32 +0000 (19:20 +0200)
committerMark Wielaard <mark@klomp.org>
Tue, 13 Apr 2021 12:45:34 +0000 (14:45 +0200)
newfd is normally created by mkstemp given the original fd exists.
Otherwise it will created by open from arfname. In the second case
newfd might not get closed. Preventd this by always trying to close
it after errout.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/ar.c

index 14cd6cacc70a8cc9d1d918653447bec8e0448c6a..f0eee7a8a5e52a69aec1e9ad9c0a7e2119509cae 100644 (file)
@@ -1,3 +1,7 @@
+2021-04-03  Mark Wielaard  <mark@klomp.org>
+
+       * ar.c (do_oper_insert): Always close newfd.
+
 2021-03-03  Mark Wielaard  <mark@klomp.org>
 
        * readelf.c (handle_symtab): Sanity check verneed vna_next,
index 66b2c4fdc4125c016e17d5e812786650bbceaa6b..ab6098f030b4c670a3babdbf698a08011430c79f 100644 (file)
--- a/src/ar.c
+++ b/src/ar.c
@@ -1566,6 +1566,9 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc,
   if (fd != -1)
     close (fd);
 
+  if (newfd != -1)
+    close (newfd);
+
   return status;
 }