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 <elder@linaro.org>
Message-Id: <20211001232338.769309-6-elder@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Alex Elder 2021-10-01 18:23:09 -05:00 committed by Bjorn Andersson
parent 405e4e2b01
commit 61da0f8fda

View File

@ -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);
}