Browse Source

JSON: Fix a memory leak on an error path

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>
Jouni Malinen 7 years ago
parent
commit
281f480c53
1 changed files with 2 additions and 0 deletions
  1. 2 0
      src/utils/json.c

+ 2 - 0
src/utils/json.c

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