Detect and display an error on leaks due to return of a function that allocates something is ignored.
This fixes #3439
This commit is contained in:
parent
45759f6f7d
commit
81318b3f4a
|
@ -2879,6 +2879,11 @@ void CheckMemoryLeakNoVar::check()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle the case were the user is calling a function returning something which is leaking
|
||||||
|
// and never assigns the returned value to a variable, which will lead to a leak.
|
||||||
|
else if (Token::Match(tok2, "[;{}] %var% (") && getAllocationType(tok2->next(), 0) != No)
|
||||||
|
missingAssignementLeak(tok2, tok2->next()->str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2888,4 +2893,9 @@ void CheckMemoryLeakNoVar::functionCallLeak(const Token *loc, const std::string
|
||||||
reportError(loc, Severity::error, "leakNoVarFunctionCall", "Allocation with " + alloc + ", " + functionCall + " doesn't release it.");
|
reportError(loc, Severity::error, "leakNoVarFunctionCall", "Allocation with " + alloc + ", " + functionCall + " doesn't release it.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CheckMemoryLeakNoVar::missingAssignementLeak(const Token *loc, const std::string &alloc)
|
||||||
|
{
|
||||||
|
reportError(loc, Severity::error, "leakNoVar", "Allocation with " + alloc + " never assigned.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -456,6 +456,8 @@ private:
|
||||||
|
|
||||||
void functionCallLeak(const Token *loc, const std::string &alloc, const std::string &functionCall);
|
void functionCallLeak(const Token *loc, const std::string &alloc, const std::string &functionCall);
|
||||||
|
|
||||||
|
void missingAssignementLeak(const Token *loc, const std::string &alloc);
|
||||||
|
|
||||||
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) const
|
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) const
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue