memleak: corrected the wrong line number (#77)

This commit is contained in:
Daniel Marjamäki 2009-02-05 20:17:01 +00:00
parent 7589dc3d16
commit 10abbda6a7
3 changed files with 14 additions and 12 deletions

View File

@ -601,7 +601,7 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
{
addtoken("use");
}
else if (Token::Match(tok, std::string("[;{}=(,+-*/] " + varnameStr + " [").c_str()))
else if (Token::Match(tok->previous(), std::string("[;{}=(,+-*/] " + varnameStr + " [").c_str()))
{
addtoken("use_");
}

View File

@ -33,6 +33,7 @@
#include "errormessage.h"
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <fstream>
@ -307,14 +308,6 @@ unsigned int CppCheck::check()
void CppCheck::checkFile(const std::string &code, const char FileName[])
{
/* For debugging: Write the code into a file and exit
{
std::ofstream f("temp.txt");
f << code;
exit(0);
}
*/
Tokenizer _tokenizer;
// Tokenize the file
@ -347,11 +340,8 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
if (ErrorMessage::charArrayIndex(_settings) || ErrorMessage::charBitOp(_settings))
checkOther.CheckCharVariable();
_tokenizer.simplifyTokenList();
if (_settings._unusedFunctions)
_checkFunctionUsage.parseTokens(_tokenizer);

View File

@ -174,6 +174,7 @@ private:
TEST_CASE(dealloc_use_4);
TEST_CASE(dealloc_use_5);
TEST_CASE(dealloc_use_6);
TEST_CASE(dealloc_use_7);
// free a free'd pointer
TEST_CASE(freefree1);
@ -1728,6 +1729,17 @@ private:
ASSERT_EQUALS(std::string(""), errout.str());
}
void dealloc_use_7()
{
check("void foo()\n"
"{\n"
" char *str = new char[10];\n"
" delete [] str;\n"
" str[10] = 0;\n"
"}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: Using \"str\" after it has been deallocated / released\n"), errout.str());
}
void freefree1()
{