Fixed #8340 (incorrect memleak errors)
This commit is contained in:
parent
5051744304
commit
75e367c48b
|
@ -364,7 +364,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
||||||
for (const Token *innerTok = tok->tokAt(2); innerTok && innerTok != closingParenthesis; innerTok = innerTok->next()) {
|
for (const Token *innerTok = tok->tokAt(2); innerTok && innerTok != closingParenthesis; innerTok = innerTok->next()) {
|
||||||
// TODO: replace with checkTokenInsideExpression()
|
// TODO: replace with checkTokenInsideExpression()
|
||||||
|
|
||||||
if (Token::Match(innerTok, "%var% =")) {
|
if (Token::Match(innerTok, "%var% =") && innerTok->astParent() == innerTok->next()) {
|
||||||
// allocation?
|
// allocation?
|
||||||
if (Token::Match(innerTok->tokAt(2), "%type% (")) {
|
if (Token::Match(innerTok->tokAt(2), "%type% (")) {
|
||||||
const Library::AllocFunc* f = mSettings->library.alloc(innerTok->tokAt(2));
|
const Library::AllocFunc* f = mSettings->library.alloc(innerTok->tokAt(2));
|
||||||
|
|
|
@ -100,6 +100,7 @@ private:
|
||||||
TEST_CASE(ifelse9); // #5273 - if (X(p==NULL, 0))
|
TEST_CASE(ifelse9); // #5273 - if (X(p==NULL, 0))
|
||||||
TEST_CASE(ifelse10); // #8794 - if (!(x!=NULL))
|
TEST_CASE(ifelse10); // #8794 - if (!(x!=NULL))
|
||||||
TEST_CASE(ifelse11); // #8365 - if (NULL == (p = malloc(4)))
|
TEST_CASE(ifelse11); // #8365 - if (NULL == (p = malloc(4)))
|
||||||
|
TEST_CASE(ifelse12); // #8340 - if ((*p = malloc(4)) == NULL)
|
||||||
|
|
||||||
// switch
|
// switch
|
||||||
TEST_CASE(switch1);
|
TEST_CASE(switch1);
|
||||||
|
@ -1172,6 +1173,14 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ifelse12() { // #8340
|
||||||
|
check("void f(char **p) {\n"
|
||||||
|
" if ((*p = malloc(4)) == NULL)\n"
|
||||||
|
" return;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void switch1() {
|
void switch1() {
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" char *p = 0;\n"
|
" char *p = 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue