Fixed #5574 (False positive: mismatchAllocDealloc using realloc() and free)
This commit is contained in:
parent
521734faa2
commit
06618b31bb
|
@ -181,9 +181,12 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
|
|||
|
||||
// Does tok2 point on "g_malloc", "g_strdup", ..
|
||||
const int alloctype = settings1->library.alloc(tok2->str());
|
||||
if (alloctype > 0)
|
||||
if (alloctype > 0) {
|
||||
if (alloctype == settings1->library.dealloc("free"))
|
||||
return Malloc;
|
||||
return Library::ismemory(alloctype) ? OtherMem : OtherRes;
|
||||
}
|
||||
}
|
||||
|
||||
while (Token::Match(tok2,"%type%|%var% ::|. %type%"))
|
||||
tok2 = tok2->tokAt(2);
|
||||
|
|
|
@ -273,6 +273,7 @@ private:
|
|||
TEST_CASE(realloc13);
|
||||
TEST_CASE(realloc14);
|
||||
TEST_CASE(realloc15);
|
||||
TEST_CASE(realloc16);
|
||||
|
||||
TEST_CASE(assign1);
|
||||
TEST_CASE(assign2); // #2806 - FP when using redundant assignment
|
||||
|
@ -3065,6 +3066,16 @@ private:
|
|||
"[test.cpp:6]: (error) Memory leak: m_options\n", errout.str());
|
||||
}
|
||||
|
||||
void realloc16() {
|
||||
check("void f(char *zLine) {\n"
|
||||
" zLine = realloc(zLine, 42);\n"
|
||||
" if (zLine) {\n"
|
||||
" free(zLine);\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void assign1() {
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue