* [COMMITTED] libasm: Fix double fclose in asm_end.
@ 2020-04-26 0:30 Mark Wielaard
0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2020-04-26 0:30 UTC (permalink / raw)
To: elfutils-devel; +Cc: Mark Wielaard
GCC10 -fanalyzer found a double fclose in asm_end. asm_end can call
text_end, which calls fclose and checks for errors, then asm_end
calls __libasm_finictx which can call fclose again (but doesn't
check for errors). Call fflush in text_end instead. fflush will
generate the same error fclose would if something went wrong writing
out the file.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
libasm/ChangeLog | 4 ++++
libasm/asm_end.c | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/libasm/ChangeLog b/libasm/ChangeLog
index 7b0d3df3..2c092abe 100644
--- a/libasm/ChangeLog
+++ b/libasm/ChangeLog
@@ -1,3 +1,7 @@
+2020-04-25 Mark Wielaard <mark@klomp.org>
+
+ * asm_end.c (text_end): Call fflush instead of fclose.
+
2020-01-08 Mark Wielaard <mark@klomp.org>
* libasm.h: Don't include libebl.h. Define an opaque Ebl handle.
diff --git a/libasm/asm_end.c b/libasm/asm_end.c
index 99e95017..3b8582fd 100644
--- a/libasm/asm_end.c
+++ b/libasm/asm_end.c
@@ -47,7 +47,7 @@
static int
text_end (AsmCtx_t *ctx __attribute__ ((unused)))
{
- if (fclose (ctx->out.file) != 0)
+ if (fflush (ctx->out.file) != 0)
{
__libasm_seterrno (ASM_E_IOERROR);
return -1;
--
2.18.2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-04-26 0:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-26 0:30 [COMMITTED] libasm: Fix double fclose in asm_end 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).