From 80c7d0f81193023f7453758305e034e89429cd41 Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Mon, 13 Mar 2023 18:14:48 +0800 Subject: [PATCH] fix: memory leak in tag json parsing --- src/parser/neu_json_tag.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/parser/neu_json_tag.c b/src/parser/neu_json_tag.c index ab1c757b..d3b98a2c 100644 --- a/src/parser/neu_json_tag.c +++ b/src/parser/neu_json_tag.c @@ -252,13 +252,18 @@ int neu_json_encode_add_tags_req(void *json_object, void *param) int ret = 0; neu_json_add_tags_req_t *req = param; - void * tag_array = neu_json_array(); - neu_json_tag_array_t arr = { + void *tag_array = neu_json_array(); + if (NULL == tag_array) { + return -1; + } + + neu_json_tag_array_t arr = { .len = req->n_tag, .tags = req->tags, }; ret = neu_json_encode_tag_array(tag_array, &arr); if (0 != ret) { + neu_json_encode_free(tag_array); return ret; } @@ -517,13 +522,18 @@ int neu_json_encode_get_tags_resp(void *json_object, void *param) int ret = 0; neu_json_get_tags_resp_t *resp = (neu_json_get_tags_resp_t *) param; - void * tag_array = neu_json_array(); - neu_json_tag_array_t arr = { + void *tag_array = neu_json_array(); + if (NULL == tag_array) { + return -1; + } + + neu_json_tag_array_t arr = { .len = resp->n_tag, .tags = resp->tags, }; ret = neu_json_encode_tag_array(tag_array, &arr); if (0 != ret) { + neu_json_encode_free(tag_array); return ret; }