From: Mark Wielaard Date: Sat, 25 Apr 2020 23:20:57 +0000 (+0200) Subject: libasm: Fix double fclose in asm_end. X-Git-Tag: elfutils-0.180~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c5bd878a940817088fd7907eb9d503ec98d3437;p=thirdparty%2Felfutils.git libasm: Fix double fclose in asm_end. 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 --- diff --git a/libasm/ChangeLog b/libasm/ChangeLog index 7b0d3df34..2c092abe1 100644 --- a/libasm/ChangeLog +++ b/libasm/ChangeLog @@ -1,3 +1,7 @@ +2020-04-25 Mark Wielaard + + * asm_end.c (text_end): Call fflush instead of fclose. + 2020-01-08 Mark Wielaard * 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 99e950170..3b8582fdd 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;