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:
Davide Caratti 2019-11-24 18:32:20 +01:00 committed by Jouni Malinen
parent 84877f253d
commit 2ba6aa6045

View File

@ -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;