aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanjay Kumar <sanjay.pec@gmail.com>2017-08-05 23:52:49 +0530
committerSanjay Kumar <sanjay.pec@gmail.com>2017-08-05 23:52:49 +0530
commit0abcbce3bbae7e1068caacedbccc1563ff005df4 (patch)
tree7b5e29345077d0b8bfe745f90a90e80eb73b2924
parent4947f9a19377ff3f2859915b4dec570e67e47757 (diff)
downloadjansson-0abcbce3bbae7e1068caacedbccc1563ff005df4.zip
jansson-0abcbce3bbae7e1068caacedbccc1563ff005df4.tar.gz
jansson-0abcbce3bbae7e1068caacedbccc1563ff005df4.tar.bz2
json_dump_file API returns success even when fclose fails (consider disk full case). API should check the return value of fclose before returning success to its caller. fwrite may not write anything into the file, it simply returns the number of bytes written into the buffer. When disk is full and fclose is called, it results in truncation of the file (resulting in zero sized file). Since, API is returning success, its caller can't take any remedial action on its failure.
-rw-r--r--src/dump.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/dump.c b/src/dump.c
index a23fabb..63a9c15 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -481,7 +481,9 @@ int json_dump_file(const json_t *json, const char *path, size_t flags)
result = json_dumpf(json, output, flags);
- fclose(output);
+ if(fclose(output) != 0)
+ return -1;
+
return result;
}