diff mbox series

fix memory leak in case allocation of token fails during JSON parsing

Message ID cff8cda6f73dd690fd2c7836175578925e2143a8.1574614584.git.davide.caratti@gmail.com
State Accepted
Headers show
Series fix memory leak in case allocation of token fails during JSON parsing | expand

Commit Message

d. caratti Nov. 24, 2019, 5:32 p.m. UTC
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 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Jouni Malinen Dec. 21, 2019, 3:49 p.m. UTC | #1
On Sun, Nov 24, 2019 at 06:32:20PM +0100, Davide Caratti wrote:
> 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().

Thanks, applied.
diff mbox series

Patch

diff --git a/src/utils/json.c b/src/utils/json.c
index 3e5e21477..9da448879 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;