-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix #14949: FP leakNoVarFunctionCall when passing resource to constructor #8765
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -517,7 +517,7 @@ void CheckMemoryLeakInClassImpl::check() | |
| // only check classes and structures | ||
| for (const Scope * scope : symbolDatabase->classAndStructScopes) { | ||
| for (const Variable &var : scope->varlist) { | ||
| if (!var.isStatic() && (var.isPointer() || var.isPointerArray())) { | ||
| if (!var.isStatic()) { | ||
| // allocation but no deallocation of private variables in public function.. | ||
| const Token *tok = var.typeStartToken(); | ||
| // Either it is of standard type or a non-derived type | ||
|
|
@@ -1046,22 +1046,20 @@ void CheckMemoryLeakNoVarImpl::checkForUnreleasedInputArgument(const Scope *scop | |
| const AllocType alloc = getAllocationType(arg, 0); | ||
| if (alloc == No) | ||
| continue; | ||
| if (alloc == New || alloc == NewArray) { | ||
| const Token* typeTok = arg->next(); | ||
| bool bail = !typeTok->isStandardType() && | ||
| (!typeTok->valueType() || | ||
| (typeTok->valueType()->type < ValueType::Type::SMART_POINTER && | ||
| typeTok->valueType()->type != ValueType::Type::POD)) && | ||
| !mSettings.library.detectContainerOrIterator(typeTok) && | ||
| !mSettings.library.podtype(typeTok->expressionString()); | ||
| if (bail && typeTok->type() && typeTok->type()->classScope && | ||
| typeTok->type()->classScope->numConstructors == 0 && | ||
| typeTok->type()->classScope->getDestructor() == nullptr) { | ||
| bail = false; | ||
| } | ||
| if (bail) | ||
| continue; | ||
| const Token* typeTok = arg->next(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not so sure
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand. Using git blame I traced those lines back to 23deadb370 and 54b9fa5523. It seems to me like they are there for a reason. Maybe they are unnecessary, but I feel that should be a separate PR. Edit: nevermind sorry I see the issue. I will see about reducing these checks.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried removing different subsets of the checks and something like based on your suggestion about checking if it's passed to a constructor but wasn't able to pass all test cases. I've got to do some other work so likely won't be able to solve this today. It might be a bit beyond my limited knowledge as most of my cppcheck hacking has been focused on the front end. |
||
| bool bail = !typeTok->isStandardType() && | ||
| (!typeTok->valueType() || | ||
| (typeTok->valueType()->type < ValueType::Type::SMART_POINTER && | ||
| typeTok->valueType()->type != ValueType::Type::POD)) && | ||
| !mSettings.library.detectContainerOrIterator(typeTok) && | ||
| !mSettings.library.podtype(typeTok->expressionString()); | ||
| if (bail && typeTok->type() && typeTok->type()->classScope && | ||
| typeTok->type()->classScope->numConstructors == 0 && | ||
| typeTok->type()->classScope->getDestructor() == nullptr) { | ||
| bail = false; | ||
| } | ||
| if (bail) | ||
| continue; | ||
| if (isReopenStandardStream(arg)) | ||
| continue; | ||
| if (tok->function()) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.