Skip to content
Open
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
3 changes: 2 additions & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ void CheckLeakAutoVarImpl::deallocReturnError(const Token *tok, const Token *dea
void CheckLeakAutoVarImpl::configurationInfo(const Token* tok, const std::pair<const Token*, VarInfo::Usage>& functionUsage)
{
if (mSettings.checkLibrary && functionUsage.second == VarInfo::USED &&
(!functionUsage.first || !functionUsage.first->function() || !functionUsage.first->function()->hasBody())) {
(!functionUsage.first || !functionUsage.first->function() || !functionUsage.first->function()->hasBody()) &&
!(functionUsage.first && mSettings.library.isUse(mSettings.library.getFunctionName(functionUsage.first)))) {
std::string funcStr = functionUsage.first ? mSettings.library.getFunctionName(functionUsage.first) : "f";
if (funcStr.empty())
funcStr = "unknown::" + functionUsage.first->str();
Expand Down
24 changes: 24 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class TestLeakAutoVar : public TestFixture {
TEST_CASE(configuration4);
TEST_CASE(configuration5);
TEST_CASE(configuration6);
TEST_CASE(configurationUse);

TEST_CASE(ptrptr);

Expand Down Expand Up @@ -3102,6 +3103,29 @@ class TestLeakAutoVar : public TestFixture {
ASSERT_EQUALS("[test.cpp:5:5]: (error) Resource leak: file [resourceLeak]\n", errout_str());
}

void configurationUse() {
// A function configured with <use> takes care of the memory, so it needs
// no further configuration.
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def format=\"2\">\n"
" <memory>\n"
" <alloc>myalloc</alloc>\n"
" <use>set_data</use>\n"
" <dealloc>myfree</dealloc>\n"
" </memory>\n"
" <function name=\"set_data\">\n"
" <noreturn>false</noreturn>\n"
" <arg nr=\"1\"/>\n"
" </function>\n"
"</def>\n";
const Settings settingsUse = settingsBuilder().libraryxml(xmldata).checkLibrary().build();
check("void f() {\n"
" char *p = myalloc(10);\n"
" set_data(p);\n"
"}\n", settingsUse);
ASSERT_EQUALS("", errout_str());
}

void configuration6() {
check("void f() {}\n" // #11198
"void g() {\n"
Expand Down
Loading