From: Davide Caratti Date: Sun, 24 Nov 2019 17:32:20 +0000 (+0100) Subject: Fix memory leak in case allocation of token fails during JSON parsing X-Git-Tag: hostap_2_10~2138 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2ba6aa60458fc7cabe211c57c44f78d753f138ec;p=thirdparty%2Fhostap.git 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 --- diff --git a/src/utils/json.c b/src/utils/json.c index 9ec7ac941..5a0edf211 100644 --- a/src/utils/json.c +++ b/src/utils/json.c @@ -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;