aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan T. Jacobsen <iantj92@gmail.com>2014-07-16 00:16:32 +0100
committerIan T. Jacobsen <iantj92@gmail.com>2014-07-16 00:16:32 +0100
commit122a1e2af99280d9112c92c26040f6bccd29fec3 (patch)
treedfa4c4fdb7db74109e6df1a02a6fe7fccf838413
parentc8d017bd8842bbaa1b15d1f49f57577089666424 (diff)
downloadjansson-122a1e2af99280d9112c92c26040f6bccd29fec3.zip
jansson-122a1e2af99280d9112c92c26040f6bccd29fec3.tar.gz
jansson-122a1e2af99280d9112c92c26040f6bccd29fec3.tar.bz2
Fixed cases where file would be opened, but not closed. And small realloc memory issue.
-rw-r--r--test/bin/json_process.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/test/bin/json_process.c b/test/bin/json_process.c
index 7ae1d06..1d0afcc 100644
--- a/test/bin/json_process.c
+++ b/test/bin/json_process.c
@@ -181,6 +181,7 @@ int use_conf(char *test_path)
if (conf.indent < 0 || conf.indent > 31) {
fprintf(stderr, "invalid value for JSON_INDENT: %d\n", conf.indent);
+ fclose(infile);
return 2;
}
if (conf.indent)
@@ -201,6 +202,7 @@ int use_conf(char *test_path)
if (conf.precision < 0 || conf.precision > 31) {
fprintf(stderr, "invalid value for JSON_REAL_PRECISION: %d\n",
conf.precision);
+ fclose(infile);
return 2;
}
if (conf.precision)
@@ -303,17 +305,19 @@ int use_env()
if(getenv_int("STRIP")) {
/* Load to memory, strip leading and trailing whitespace */
size_t size = 0, used = 0;
- char *buffer = NULL;
+ char *buffer = NULL, *buf_ck = NULL;
while(1) {
size_t count;
size = (size == 0 ? 128 : size * 2);
- buffer = realloc(buffer, size);
- if(!buffer) {
+ buf_ck = realloc(buffer, size);
+ if(!buf_ck) {
fprintf(stderr, "Unable to allocate %d bytes\n", (int)size);
+ free(buffer);
return 1;
}
+ buffer = buf_ck;
count = fread(buffer + used, 1, size - used, stdin);
if(count < size - used) {