summaryrefslogtreecommitdiffhomepage
path: root/lib.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-02-03 11:49:14 +0100
committerJo-Philipp Wich <jo@mein.io>2022-02-03 17:04:05 +0100
commitd5003fde57eab19588da7bfdbaefe93d47435eb6 (patch)
treeeab61f9e563bb78f2648f9a0bdb11c672342fd25 /lib.c
parent5d0ecd9aefee1be2b51713f7343939b7039a0406 (diff)
lib: fix leaking tokener in uc_json() on parse exception
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/lib.c b/lib.c
index 7ae9a51..5ad08e7 100644
--- a/lib.c
+++ b/lib.c
@@ -2048,10 +2048,10 @@ uc_replace(uc_vm_t *vm, size_t nargs)
static uc_value_t *
uc_json(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *rv, *src = uc_fn_arg(0);
+ uc_value_t *rv = NULL, *src = uc_fn_arg(0);
struct json_tokener *tok = NULL;
enum json_tokener_error err;
- json_object *jso;
+ json_object *jso = NULL;
const char *str;
size_t len;
@@ -2073,32 +2073,30 @@ uc_json(uc_vm_t *vm, size_t nargs)
err = json_tokener_get_error(tok);
if (err == json_tokener_continue) {
- json_object_put(jso);
uc_vm_raise_exception(vm, EXCEPTION_SYNTAX,
"Unexpected end of string in JSON data");
- return NULL;
+ goto out;
}
else if (err != json_tokener_success) {
- json_object_put(jso);
uc_vm_raise_exception(vm, EXCEPTION_SYNTAX,
"Failed to parse JSON string: %s",
json_tokener_error_desc(err));
- return NULL;
+ goto out;
}
else if (json_tokener_get_parse_end(tok) < len) {
- json_object_put(jso);
uc_vm_raise_exception(vm, EXCEPTION_SYNTAX,
"Trailing garbage after JSON data");
- return NULL;
+ goto out;
}
- json_tokener_free(tok);
rv = ucv_from_json(vm, jso);
+out:
+ json_tokener_free(tok);
json_object_put(jso);
return rv;