From 19c11750643cff6279cabac8939823dbf8aca24c Mon Sep 17 00:00:00 2001 From: Krzysztof Gabis Date: Thu, 3 Mar 2016 18:52:30 +0000 Subject: [PATCH] Fixes a bug where fopen() error was being ignored. --- parson.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/parson.c b/parson.c index c976710..112d742 100644 --- a/parson.c +++ b/parson.c @@ -1237,13 +1237,15 @@ JSON_Status json_serialize_to_file(const JSON_Value *value, const char *filename return JSONFailure; } fp = fopen (filename, "w"); - if (fp != NULL) { - if (fputs (serialized_string, fp) == EOF) { - return_code = JSONFailure; - } - if (fclose (fp) == EOF) { - return_code = JSONFailure; - } + if (fp == NULL) { + json_free_serialized_string(serialized_string); + return JSONFailure; + } + if (fputs(serialized_string, fp) == EOF) { + return_code = JSONFailure; + } + if (fclose(fp) == EOF) { + return_code = JSONFailure; } json_free_serialized_string(serialized_string); return return_code; @@ -1292,13 +1294,15 @@ JSON_Status json_serialize_to_file_pretty(const JSON_Value *value, const char *f return JSONFailure; } fp = fopen (filename, "w"); - if (fp != NULL) { - if (fputs (serialized_string, fp) == EOF) { - return_code = JSONFailure; - } - if (fclose (fp) == EOF) { - return_code = JSONFailure; - } + if (fp == NULL) { + json_free_serialized_string(serialized_string); + return JSONFailure; + } + if (fputs(serialized_string, fp) == EOF) { + return_code = JSONFailure; + } + if (fclose(fp) == EOF) { + return_code = JSONFailure; } json_free_serialized_string(serialized_string); return return_code;