summaryrefslogtreecommitdiff
path: root/jv_file.c
diff options
context:
space:
mode:
authorNicolas Williams <nico@cryptonector.com>2015-05-29 11:48:10 -0500
committerNicolas Williams <nico@cryptonector.com>2015-05-29 11:48:10 -0500
commit4451c08007401d1ff43973a519cf9788276afcb6 (patch)
treea6d8237b18b25ee8fe71e4481feea7a89afec38f /jv_file.c
parent89c57f79362d65f0507f59ffdb0974b364e90416 (diff)
downloadjq-4451c08007401d1ff43973a519cf9788276afcb6.tar.gz
Fix jv_load_file() (partial fix #799)
Diffstat (limited to 'jv_file.c')
-rw-r--r--jv_file.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/jv_file.c b/jv_file.c
index a633160..17c99c6 100644
--- a/jv_file.c
+++ b/jv_file.c
@@ -30,14 +30,18 @@ jv jv_load_file(const char* filename, int raw) {
jv value;
while (jv_is_valid((value = jv_parser_next(parser))))
data = jv_array_append(data, value);
- jv_free(value);
+ if (jv_invalid_has_msg(jv_copy(value))) {
+ jv_free(data);
+ data = value;
+ value = jv_invalid();
+ break;
+ }
}
}
if (!raw)
jv_parser_free(parser);
int badread = ferror(file);
- fclose(file);
- if (badread) {
+ if (fclose(file) != 0 || badread) {
jv_free(data);
return jv_invalid_with_msg(jv_string_fmt("Error reading from %s",
filename));