Remove extra reference actions in parsers.

Make parse_object use json_object_set_new_nocheck and make parse_array
use json_array_append_new, remove json_decref from error and success
paths.

Fixes #376
This commit is contained in:
Corey Farrell 2017-11-14 23:46:08 -05:00
parent 009ffa3fc8
commit bd91753e91

View File

@ -738,13 +738,11 @@ static json_t *parse_object(lex_t *lex, size_t flags, json_error_t *error)
goto error; goto error;
} }
if(json_object_set_nocheck(object, key, value)) { if(json_object_set_new_nocheck(object, key, value)) {
jsonp_free(key); jsonp_free(key);
json_decref(value);
goto error; goto error;
} }
json_decref(value);
jsonp_free(key); jsonp_free(key);
lex_scan(lex, error); lex_scan(lex, error);
@ -781,11 +779,9 @@ static json_t *parse_array(lex_t *lex, size_t flags, json_error_t *error)
if(!elem) if(!elem)
goto error; goto error;
if(json_array_append(array, elem)) { if(json_array_append_new(array, elem)) {
json_decref(elem);
goto error; goto error;
} }
json_decref(elem);
lex_scan(lex, error); lex_scan(lex, error);
if(lex->token != ',') if(lex->token != ',')