aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/util.c b/src/util.c
index 001180e..e84a72a 100644
--- a/src/util.c
+++ b/src/util.c
@@ -10,28 +10,31 @@
int json_streaming_read(FILE *stream, cJSON **json)
{
- int ret;
size_t n;
+ int ret;
char *line = NULL;
ret = getline(&line, &n, stream);
if (ret < 0) {
if (errno != 0) {
print_err("%s", strerror(errno));
- return -errno;
+ ret = -errno;
}
+ ret = -EOF;
- return -EOF;
+ goto out_free_line;
}
*json = cJSON_Parse(line);
- free(line);
if (cJSON_IsInvalid(*json)) {
print_err("%s", "Invalid JSON");
- return -EPERM;
+ ret = -EPERM;
+ goto out_free_line;
}
- return 0;
+out_free_line:
+ free(line);
+ return ret;
}
int vpopen(FILE **stream, const char *file, char *const argv[])