Fix #14949: FP leakNoVarFunctionCall when passing resource to constructor - #8765
Fix #14949: FP leakNoVarFunctionCall when passing resource to constructor#8765aadanen wants to merge 4 commits into
Conversation
|
clang-tidy/build fails with sanitizers/build fails with a timeout. As I anticipated this solution is too slow. I will think about how to make it faster. |
It does that all the time, I'll rerun it later... |
| for (const Scope * scope : symbolDatabase->classAndStructScopes) { | ||
| for (const Variable &var : scope->varlist) { | ||
| if (!var.isStatic() && (var.isPointer() || var.isPointerArray())) { | ||
| if (!var.isStatic()) { |
There was a problem hiding this comment.
I don't think this has any affect in this case. This check only considers members that are allocated in the constructor.
There was a problem hiding this comment.
You are correct that it is irrelevant to this bug and I will revert the change. I made the change because I was a little confused and it is "wrong" for the same reason. Sorry!
I still think the change should be made because it makes the following enhancement:
struct S {
explicit S(char *name) {
m_fd = mkstemp(name); // file is not closed in destructor
}
int m_fd = -1;
};
S g(char *name) {
return S(name);
}
void f(char* ptr) {
S s = g(ptr);
}
(reports nothing) (requires --library=posix)
struct S {
explicit S() {
mem = malloc(42); // memory not freed in destructor
}
int *mem = NULL;
};
S g() {
return S();
}
void f() {
S s = g();
}
(reports unsafeClassError)
but that should be a separate bug and PR because its different and also it would be an "enhancement" instead of a "false positive". Should I make another forum post?
Remove Variable and AllocType type checking when searching for unreleased arguments and when checking if member variables are deallocated in destructor.
This method is a little heavy handed and might hurt performance, but I am unsure how we could be more precise. It would be nice if we could check "If var.isResource() or var.needsToBeDeallocated()" but that would be a different PR i think.