Skip to content

Commit

Permalink
Fix crash in CheckLeakAutoVar (f'up to #12186) (#5683)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Nov 20, 2023
1 parent 036df0a commit d7c7a39
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1109,8 +1109,8 @@ void CheckLeakAutoVar::ret(const Token *tok, VarInfo &varInfo, const bool isEndO
}

// don't warn when returning after checking return value of outparam allocation
const Scope* scope = tok->scope();
if (scope->type == Scope::ScopeType::eIf || scope->type== Scope::ScopeType::eElse) {
if (it->second.allocTok && (tok->scope()->type == Scope::ScopeType::eIf || tok->scope()->type== Scope::ScopeType::eElse)) {
const Scope* scope = tok->scope();
if (scope->type == Scope::ScopeType::eElse) {
scope = scope->bodyStart->tokAt(-2)->scope();
}
Expand Down
10 changes: 10 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,16 @@ class TestLeakAutoVar : public TestFixture {
" s->p = NULL;\n"
"}\n");
ASSERT_EQUALS("", errout.str());

const Settings s = settingsBuilder().library("std.cfg").build();
check("struct S {};\n"
"void f(int i, std::vector<std::unique_ptr<S>> &v) {\n"
" if (i < 1) {\n"
" auto s = new S;\n"
" v.push_back(std::unique_ptr<S>(s));\n"
" }\n"
"}\n", &s);
ASSERT_EQUALS("", errout.str()); // don't crash
}

void goto1() {
Expand Down

0 comments on commit d7c7a39

Please sign in to comment.