fixed #12111 - memory leak with `-j2` and `--cppcheck-build-dir` (#5589)

This commit is contained in:
Oliver Stöneberg 2023-12-17 15:07:13 +01:00 committed by GitHub
parent f2622a673f
commit 086ceea333
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 8 deletions

View File

@ -1097,12 +1097,13 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
if (mSettings.useSingleJob() || !mSettings.buildDir.empty()) {
// Analyse the tokens..
CTU::FileInfo *fi1 = CTU::getFileInfo(&tokenizer);
if (fi1) {
if (mSettings.useSingleJob())
mFileInfo.push_back(fi1);
if (CTU::FileInfo * const fi1 = CTU::getFileInfo(&tokenizer)) {
if (!mSettings.buildDir.empty())
mAnalyzerInformation.setFileInfo("ctu", fi1->toString());
if (mSettings.useSingleJob())
mFileInfo.push_back(fi1);
else
delete fi1;
}
// cppcheck-suppress shadowFunction - TODO: fix this
@ -1110,12 +1111,13 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
if (doUnusedFunctionOnly && dynamic_cast<const CheckUnusedFunctions*>(check) == nullptr)
continue;
Check::FileInfo *fi = check->getFileInfo(&tokenizer, &mSettings);
if (fi != nullptr) {
if (mSettings.useSingleJob())
mFileInfo.push_back(fi);
if (Check::FileInfo * const fi = check->getFileInfo(&tokenizer, &mSettings)) {
if (!mSettings.buildDir.empty())
mAnalyzerInformation.setFileInfo(check->name(), fi->toString());
if (mSettings.useSingleJob())
mFileInfo.push_back(fi);
else
delete fi;
}
}
}

View File

@ -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)