From: Michael Wallner Date: Tue, 28 Mar 2017 17:49:05 +0000 (+0200) Subject: fix leak X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=b1d875d13e5a8f7600d3df6b44c75e8613cfe509;p=m6w6%2Fext-psi fix leak --- diff --git a/src/cpp.c b/src/cpp.c index e79a563..2cf4094 100644 --- a/src/cpp.c +++ b/src/cpp.c @@ -281,17 +281,20 @@ static bool psi_cpp_stage2(struct psi_cpp *cpp) if (is_eol) { size_t processed = 0; + bool parsed = psi_parser_process(cpp->parser, parser_tokens, &processed); - if (!psi_parser_process(cpp->parser, parser_tokens, &processed)) { - psi_plist_free(parser_tokens); - return false; - } + /* EOL */ psi_plist_pop(parser_tokens, NULL); psi_plist_clean(parser_tokens); do_cpp = false; + + if (!parsed) { + psi_plist_free(parser_tokens); + return false; + } } else { /* leave EOLs in the input stream, else we might end up - * with a hash not preceeded with a new line after include */ + * with a hash not preceded with a new line after include */ psi_cpp_tokiter_del_cur(cpp, false); } diff --git a/src/parser.c b/src/parser.c index 947eea7..434554e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.16 on Tue Mar 28 16:36:22 2017 */ +/* Generated by re2c 0.16 on Tue Mar 28 19:45:29 2017 */ #line 1 "src/parser.re" /******************************************************************************* Copyright (c) 2016, Michael Wallner . @@ -183,10 +183,10 @@ static void psi_parser_register_constants(struct psi_parser *P) } #endif -struct psi_plist *psi_parser_preprocess(struct psi_parser *P, struct psi_plist *tokens) +struct psi_plist *psi_parser_preprocess(struct psi_parser *P, struct psi_plist **tokens) { - if (psi_cpp_process(P->preproc, &tokens)) { - return tokens; + if (psi_cpp_process(P->preproc, tokens)) { + return *tokens; } return NULL; } @@ -208,7 +208,7 @@ bool psi_parser_parse(struct psi_parser *P, struct psi_parser_input *I) return false; } - if (!(preproc = psi_parser_preprocess(P, scanned))) { + if (!(preproc = psi_parser_preprocess(P, &scanned))) { psi_plist_free(scanned); return false; } diff --git a/src/parser.h b/src/parser.h index b05d185..65c9012 100644 --- a/src/parser.h +++ b/src/parser.h @@ -66,7 +66,7 @@ struct psi_parser *psi_parser_init(struct psi_parser *P, psi_error_cb error, uns struct psi_parser_input *psi_parser_open_file(struct psi_parser *P, const char *filename, bool report_errors); struct psi_parser_input *psi_parser_open_string(struct psi_parser *P, const char *string, size_t length); struct psi_plist *psi_parser_scan(struct psi_parser *P, struct psi_parser_input *I); -struct psi_plist *psi_parser_preprocess(struct psi_parser *P, struct psi_plist *tokens); +struct psi_plist *psi_parser_preprocess(struct psi_parser *P, struct psi_plist **tokens); bool psi_parser_process(struct psi_parser *P, struct psi_plist *tokens, size_t *processed); bool psi_parser_parse(struct psi_parser *P, struct psi_parser_input *I); void psi_parser_dtor(struct psi_parser *P); diff --git a/src/parser.re b/src/parser.re index 59c8bda..a313ac9 100644 --- a/src/parser.re +++ b/src/parser.re @@ -181,10 +181,10 @@ static void psi_parser_register_constants(struct psi_parser *P) } #endif -struct psi_plist *psi_parser_preprocess(struct psi_parser *P, struct psi_plist *tokens) +struct psi_plist *psi_parser_preprocess(struct psi_parser *P, struct psi_plist **tokens) { - if (psi_cpp_process(P->preproc, &tokens)) { - return tokens; + if (psi_cpp_process(P->preproc, tokens)) { + return *tokens; } return NULL; } @@ -206,7 +206,7 @@ bool psi_parser_parse(struct psi_parser *P, struct psi_parser_input *I) return false; } - if (!(preproc = psi_parser_preprocess(P, scanned))) { + if (!(preproc = psi_parser_preprocess(P, &scanned))) { psi_plist_free(scanned); return false; }