Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,25 +1097,27 @@ 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
for (const Check *check : Check::instances()) {
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;
}
}
}
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)
Loading