]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
JSON: Fix a memory leak on an error path
authorJouni Malinen <jouni@qca.qualcomm.com>
Wed, 29 Nov 2017 11:22:44 +0000 (13:22 +0200)
committerJouni Malinen <j@w1.fi>
Wed, 29 Nov 2017 11:22:44 +0000 (13:22 +0200)
If the second json_alloc_token() call failed to allocate memory,
json_parse() missed the first allocation on the error path. Assign the
root pointer earlier for that case to avoid the potential memory leak.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
src/utils/json.c

index eae627d87dd0b72d9dbbcedaee73c2f3ef7d4774..b9130d3a65ab048b9f6ae3b60f1f48dade7d5dbd 100644 (file)
@@ -230,6 +230,8 @@ struct json_token * json_parse(const char *data, size_t data_len)
                                token = json_alloc_token(&tokens);
                                if (!token)
                                        goto fail;
+                               if (!root)
+                                       root = token;
                        } else if (curr_token->state == JSON_WAITING_VALUE) {
                                token = curr_token;
                        } else if (curr_token->parent &&