public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ar: Always close newfd in do_oper_insert.
@ 2021-04-03 17:24 Mark Wielaard
  2021-04-13 12:45 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2021-04-03 17:24 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

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 | 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  <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,
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ar: Always close newfd in do_oper_insert.
  2021-04-03 17:24 [PATCH] ar: Always close newfd in do_oper_insert Mark Wielaard
@ 2021-04-13 12:45 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2021-04-13 12:45 UTC (permalink / raw)
  To: elfutils-devel

On Sat, Apr 03, 2021 at 07:24:42PM +0200, Mark Wielaard wrote:
> 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.

Pushed.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-13 12:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-03 17:24 [PATCH] ar: Always close newfd in do_oper_insert Mark Wielaard
2021-04-13 12:45 ` Mark Wielaard

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