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 <m...@klomp.org>
---
 src/ChangeLog | 4 ++++
 src/ar.c      | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/src/ChangeLog b/src/ChangeLog
index 14cd6cac..f0eee7a8 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2021-04-03  Mark Wielaard  <m...@klomp.org>
+
+       * ar.c (do_oper_insert): Always close newfd.
+
 2021-03-03  Mark Wielaard  <m...@klomp.org>
 
        * readelf.c (handle_symtab): Sanity check verneed vna_next,
diff --git a/src/ar.c b/src/ar.c
index 66b2c4fd..ab6098f0 100644
--- 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;
 }
 
-- 
2.18.4

Reply via email to