aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-parser.c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2021-02-10 12:07:10 -0500
committerMarek Polacek <polacek@redhat.com>2021-02-10 22:17:43 -0500
commit27a804bc62805aedb1b097a00eb2c0059244680a (patch)
treee01d31872c8d23236b943ecd2b633600e9dae569 /gcc/c/c-parser.c
parent4b37c3ea8ab037292b0fcd62d4193ba1c2e657fe (diff)
downloadgcc-27a804bc62805aedb1b097a00eb2c0059244680a.zip
gcc-27a804bc62805aedb1b097a00eb2c0059244680a.tar.gz
gcc-27a804bc62805aedb1b097a00eb2c0059244680a.tar.bz2
c, c++: Plug -Wduplicated-cond memory leaks [PR99057]
Freeing the condition chain needs to use vec_free which does ->release, or we leak memory. gcc/c/ChangeLog: * c-parser.c (c_parser_if_statement): Use vec_free. gcc/cp/ChangeLog: * parser.c (cp_parser_selection_statement): Use vec_free.
Diffstat (limited to 'gcc/c/c-parser.c')
-rw-r--r--gcc/c/c-parser.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index a8df208..2a49d07 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -6499,12 +6499,9 @@ c_parser_if_statement (c_parser *parser, bool *if_p, vec<tree> *chain)
chain->safe_push (cond);
}
else if (!c_parser_next_token_is_keyword (parser, RID_IF))
- {
- /* This is if-else without subsequent if. Zap the condition
- chain; we would have already warned at this point. */
- delete chain;
- chain = NULL;
- }
+ /* This is if-else without subsequent if. Zap the condition
+ chain; we would have already warned at this point. */
+ vec_free (chain);
}
second_body = c_parser_else_body (parser, else_tinfo, chain);
/* Set IF_P to true to indicate that this if statement has an
@@ -6524,12 +6521,9 @@ c_parser_if_statement (c_parser *parser, bool *if_p, vec<tree> *chain)
"suggest explicit braces to avoid ambiguous %<else%>");
if (warn_duplicated_cond)
- {
- /* This if statement does not have an else clause. We don't
- need the condition chain anymore. */
- delete chain;
- chain = NULL;
- }
+ /* This if statement does not have an else clause. We don't
+ need the condition chain anymore. */
+ vec_free (chain);
}
c_finish_if_stmt (loc, cond, first_body, second_body);
add_stmt (c_end_compound_stmt (loc, block, flag_isoc99));