Memory leaks: Fixed two todo testcases (getcode handling of asprintf)
This commit is contained in:
parent
ab047c680c
commit
406fdd3219
|
@ -627,9 +627,20 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
||||||
if (parlevel == 0 && tok->str() == ";")
|
if (parlevel == 0 && tok->str() == ";")
|
||||||
addtoken(";");
|
addtoken(";");
|
||||||
|
|
||||||
if (varid && Token::Match(tok->previous(), "[(;{}] %varid% =", varid))
|
if (Token::Match(tok->previous(), "[(;{}] %varid% =", varid) ||
|
||||||
|
Token::Match(tok, "asprintf ( & %varid% ,", varid))
|
||||||
{
|
{
|
||||||
AllocType alloc = getAllocationType(tok->tokAt(2), varid);
|
AllocType alloc;
|
||||||
|
|
||||||
|
if (Token::simpleMatch(tok, "asprintf ("))
|
||||||
|
{
|
||||||
|
alloc = Malloc;
|
||||||
|
tok = tok->next()->link();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
alloc = getAllocationType(tok->tokAt(2), varid);
|
||||||
|
}
|
||||||
bool realloc = false;
|
bool realloc = false;
|
||||||
|
|
||||||
if (sz > 1 &&
|
if (sz > 1 &&
|
||||||
|
|
|
@ -351,8 +351,8 @@ private:
|
||||||
ASSERT_EQUALS(";;do{}loop;", getcode("char *s; do { } while (a);", "s"));
|
ASSERT_EQUALS(";;do{}loop;", getcode("char *s; do { } while (a);", "s"));
|
||||||
|
|
||||||
// asprintf..
|
// asprintf..
|
||||||
TODO_ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"xyz\");", "s"));
|
ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"xyz\");", "s"));
|
||||||
TODO_ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"s: %s\", s);", "s"));
|
ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"s: %s\", s);", "s"));
|
||||||
ASSERT_EQUALS(";;;", getcode("char *s; asprintf(&p, \"s: %s\", s);", "s"));
|
ASSERT_EQUALS(";;;", getcode("char *s; asprintf(&p, \"s: %s\", s);", "s"));
|
||||||
|
|
||||||
// use..
|
// use..
|
||||||
|
|
Loading…
Reference in New Issue