From 61da0f8fda6852d1e3e3aaeb9bebeb1338d8479c Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Fri, 1 Oct 2021 18:23:09 -0500 Subject: [PATCH] parser: free unused type token strings In qmi_message_parse(), the type token for each field parsed will contain a dynamically-allocated string continaing the field type. We only use the type identifier (number) though, and as a result the type name gets leaked. Fix this by freeing the type token string if non-null. Essentially the same thing occurs in qmi_struct_parse() while parsing the fields of a message. Fix the problem there as well. Signed-off-by: Alex Elder Message-Id: <20211001232338.769309-6-elder@linaro.org> Signed-off-by: Bjorn Andersson --- parser.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/parser.c b/parser.c index 19dcf35..fe645f4 100644 --- a/parser.c +++ b/parser.c @@ -325,6 +325,8 @@ static void qmi_message_parse(enum message_type message_type) qmm = calloc(1, sizeof(struct qmi_message_member)); qmm->name = id_tok.str; qmm->type = type_tok.num; + if (type_tok.str) + free(type_tok.str); qmm->qmi_struct = type_tok.qmi_struct; qmm->id = num_tok.num; qmm->required = required; @@ -367,6 +369,8 @@ static void qmi_struct_parse(void) qsm = malloc(sizeof(struct qmi_struct_member)); qsm->name = id_tok.str; qsm->type = type_tok.num; + if (type_tok.str) + free(type_tok.str); list_add(&qs->members, &qsm->node); }