From 4654bdc2347610a6f69793835159e26abd54e6bc Mon Sep 17 00:00:00 2001 From: Christian Beer Date: Wed, 4 Nov 2015 14:44:45 +0100 Subject: [PATCH] Lib: check return value This does not break compatibility because the current caller CLIENT_STATE::write_state_file() is opening the file again for each retry if MFILE::close() fails. fixes CID 34502 found by Coverity --- lib/mfile.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/mfile.cpp b/lib/mfile.cpp index 40d3400c39..31a40cb7ef 100644 --- a/lib/mfile.cpp +++ b/lib/mfile.cpp @@ -148,10 +148,13 @@ int MFILE::puts(const char* p) { return n; } +// This is closing the file even if it couldn't flush it. +// The caller needs to check the return value and open the file again before the next retry. +// int MFILE::close() { int retval = 0; if (f) { - flush(); + retval = flush(); fclose(f); f = NULL; }