summaryrefslogtreecommitdiffhomepage
path: root/lib.c
diff options
context:
space:
mode:
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;