]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Fix memory leak in case allocation of token fails during JSON parsing
authorDavide Caratti <davide.caratti@gmail.com>
Sun, 24 Nov 2019 17:32:20 +0000 (18:32 +0100)
committerJouni Malinen <j@w1.fi>
Sat, 21 Dec 2019 15:32:19 +0000 (17:32 +0200)
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>
src/utils/json.c

index 9ec7ac941a65d4c5daa3282063248c2c1b7ee263..5a0edf21145ba2368e76a0da64ffe8fa0795f902 100644 (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;