Fix memory leak in case allocation of token fails during JSON parsing
On failure of json_alloc_token(), json_parse() can return without freeing 'str' previously allocated by json_parse_string(). Fix this adding proper call to os_free(). Signed-off-by: Davide Caratti <davide.caratti@gmail.com>
This commit is contained in:
parent
84877f253d
commit
2ba6aa6045
1 changed files with 3 additions and 1 deletions
|
@ -300,8 +300,10 @@ struct json_token * json_parse(const char *data, size_t data_len)
|
|||
goto fail;
|
||||
if (!curr_token) {
|
||||
token = json_alloc_token(&tokens);
|
||||
if (!token)
|
||||
if (!token) {
|
||||
os_free(str);
|
||||
goto fail;
|
||||
}
|
||||
token->type = JSON_STRING;
|
||||
token->string = str;
|
||||
token->state = JSON_COMPLETED;
|
||||
|
|
Loading…
Reference in a new issue