Memory leaks: handling asprintf better
This commit is contained in:
parent
406fdd3219
commit
de9e62e90a
|
@ -634,6 +634,12 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
|||
|
||||
if (Token::simpleMatch(tok, "asprintf ("))
|
||||
{
|
||||
// todo: check how the return value is used.
|
||||
if (!Token::Match(tok->previous(), "[;{}]"))
|
||||
{
|
||||
Tokenizer::deleteTokens(rethead);
|
||||
return 0;
|
||||
}
|
||||
alloc = Malloc;
|
||||
tok = tok->next()->link();
|
||||
}
|
||||
|
|
|
@ -355,6 +355,10 @@ private:
|
|||
ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"s: %s\", s);", "s"));
|
||||
ASSERT_EQUALS(";;;", getcode("char *s; asprintf(&p, \"s: %s\", s);", "s"));
|
||||
|
||||
// Since we don't check how the return value is used we must bail out
|
||||
ASSERT_EQUALS("", getcode("char *s; int ret = asprintf(&s, \"xyz\");", "s"));
|
||||
TODO_ASSERT_EQUALS(";;alloc;", getcode("char *s; int ret; ret=asprintf(&s, \"xyz\"); if (ret==-1) return;", "s"));
|
||||
|
||||
// use..
|
||||
ASSERT_EQUALS(";;use;", getcode("char *s; DeleteString(s);", "s"));
|
||||
ASSERT_EQUALS(";;use;", getcode("char *s; s2 = s;", "s"));
|
||||
|
|
Loading…
Reference in New Issue