Skip to content

Commit

Permalink
fixed #12111 - memory leak with -j2 and --cppcheck-build-dir
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Dec 16, 2023
1 parent 6550554 commit 833c105
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,8 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
mAnalyzerInformation.setFileInfo("ctu", fi1->toString());
if (mSettings.useSingleJob())
mFileInfo.push_back(fi1);
else
delete fi1;
}

// cppcheck-suppress shadowFunction - TODO: fix this
Expand All @@ -1114,6 +1116,8 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
mAnalyzerInformation.setFileInfo(check->name(), fi->toString());
if (mSettings.useSingleJob())
mFileInfo.push_back(fi);
else
delete fi;
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/cli/test-other.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,3 +843,19 @@ def test_file_ignore(tmpdir):
]

assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)


def test_build_dir_j_memleak(tmpdir): #12111
build_dir = os.path.join(tmpdir, 'build-dir')
os.mkdir(build_dir)

test_file = os.path.join(tmpdir, 'test.cpp')
with open(test_file, 'wt') as f:
f.write('int main() {}')

args = ['--cppcheck-build-dir={}'.format(build_dir), '-j2', test_file]
out_lines = [
'Checking {} ...'.format(test_file)
]

assert_cppcheck(args, ec_exp=0, err_exp=[], out_exp=out_lines)

0 comments on commit 833c105

Please sign in to comment.