protobuf: fix leaking tokens
Move scanner destroy call to pbl_clear_state() so it is freed if parsing fails. This eliminates most of leaked memory reported in #17305.
This commit is contained in:
parent
1c59f7d9ac
commit
5bbfee2ed8
|
@ -571,10 +571,14 @@ pbl_clear_state(protobuf_lang_state_t *state, pbl_descriptor_pool_t* pool)
|
|||
|
||||
state->pool = NULL;
|
||||
state->file = NULL;
|
||||
state->scanner = NULL;
|
||||
state->grammar_error = FALSE;
|
||||
state->tmp_token = NULL;
|
||||
|
||||
if (state->scanner) {
|
||||
protobuf_lang_lex_destroy(state->scanner);
|
||||
state->scanner = NULL;
|
||||
}
|
||||
|
||||
if (state->pParser) {
|
||||
ProtobufLangParserFree(state->pParser, g_free);
|
||||
state->pParser = NULL;
|
||||
|
@ -664,8 +668,6 @@ int run_pbl_parser(pbl_descriptor_pool_t* pool)
|
|||
ProtobufLangParser(state.pParser, 0, NULL, &state);
|
||||
}
|
||||
|
||||
protobuf_lang_lex_destroy(scanner);
|
||||
|
||||
/* remove the parsed file from list */
|
||||
pool->proto_files_to_be_parsed = it = g_slist_delete_link(pool->proto_files_to_be_parsed, it);
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ strdup_and_store(void* yyscanner, const char* text);
|
|||
|
||||
#define PROTOBUF_LANG_PARSE(token_type) \
|
||||
protobuf_lang_get_extra(yyscanner)->tmp_token = g_new0(protobuf_lang_token_t, 1); \
|
||||
pbl_store_struct_token(protobuf_lang_get_extra(yyscanner), protobuf_lang_get_extra(yyscanner)->tmp_token); \
|
||||
protobuf_lang_get_extra(yyscanner)->tmp_token->v = strdup_and_store(yyscanner, yytext); \
|
||||
protobuf_lang_get_extra(yyscanner)->tmp_token->ln = protobuf_lang_get_lineno(yyscanner); \
|
||||
return (token_type);
|
||||
|
|
Loading…
Reference in New Issue