mirror of
https://github.com/linux-msm/qmic.git
synced 2024-11-23 17:54:01 +08:00
parser: free unused token strings in token_accept()
If token_accept() is provided a null token pointer argument, the previous "current" token is discarded. If the token matched is a symbol type, the token string (which will have been dynamically allocated in yylex()) will be leaked. Fix this by freeing the current token string if token pointer passed is null. The compiler warns when we attempt to free a pointer to constant data, so change the type of the string pointer in the symbol structure to be pointer to non-constant. Signed-off-by: Alex Elder <elder@linaro.org> Message-Id: <20211001232338.769309-5-elder@linaro.org> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
parent
23710a79b3
commit
405e4e2b01
4
parser.c
4
parser.c
@ -32,7 +32,7 @@ enum {
|
||||
|
||||
struct token {
|
||||
int id;
|
||||
const char *str;
|
||||
char *str;
|
||||
unsigned num;
|
||||
struct qmi_struct *qmi_struct;
|
||||
};
|
||||
@ -206,6 +206,8 @@ static int token_accept(int id, struct token *tok)
|
||||
if (curr_token.id == id) {
|
||||
if (tok)
|
||||
*tok = curr_token;
|
||||
else if (curr_token.str)
|
||||
free(curr_token.str);
|
||||
|
||||
curr_token = yylex();
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user