Skip to content

Commit

Permalink
fix/leak (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
katataku authored Jul 30, 2022
1 parent 586b149 commit 53b27a1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions srcs/Config/Token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ void Token::Consume(Token** tok, const std::string& expect_val) {
expect_val + " but got Nothing");
}
if ((*tok)->val() == expect_val) {
Token* old = (*tok);
*tok = (*tok)->next_token();
delete old;
return;
}
throw std::runtime_error("Consume Token failed: expected: " + expect_val +
Expand All @@ -63,7 +65,9 @@ void Token::Consume(Token** tok, TokenKind kind) {
" but got Nothing");
}
if ((*tok)->kind() == kind) {
Token* old = (*tok);
*tok = (*tok)->next_token();
delete old;
return;
}
throw std::runtime_error("Consume Token failed");
Expand Down Expand Up @@ -99,7 +103,9 @@ bool Token::Expect(Token** tok, const std::string& expect_val) {
expect_val + " but got Nothing");
}
if ((*tok)->val() == expect_val) {
Token* old = (*tok);
*tok = (*tok)->next_token();
delete old;
return true;
}
return false;
Expand All @@ -111,7 +117,9 @@ bool Token::Expect(Token** tok, TokenKind kind) {
" but got Nothing");
}
if ((*tok)->kind() == kind) {
Token* old = (*tok);
*tok = (*tok)->next_token();
delete old;
return true;
}
return false;
Expand Down

0 comments on commit 53b27a1

Please sign in to comment.