memleak: corrected the wrong line number (#77)
This commit is contained in:
parent
7589dc3d16
commit
10abbda6a7
|
@ -601,7 +601,7 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
|
||||||
{
|
{
|
||||||
addtoken("use");
|
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_");
|
addtoken("use_");
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "errormessage.h"
|
#include "errormessage.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -307,14 +308,6 @@ unsigned int CppCheck::check()
|
||||||
|
|
||||||
void CppCheck::checkFile(const std::string &code, const char FileName[])
|
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;
|
Tokenizer _tokenizer;
|
||||||
|
|
||||||
// Tokenize the file
|
// Tokenize the file
|
||||||
|
@ -347,11 +340,8 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
||||||
if (ErrorMessage::charArrayIndex(_settings) || ErrorMessage::charBitOp(_settings))
|
if (ErrorMessage::charArrayIndex(_settings) || ErrorMessage::charBitOp(_settings))
|
||||||
checkOther.CheckCharVariable();
|
checkOther.CheckCharVariable();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_tokenizer.simplifyTokenList();
|
_tokenizer.simplifyTokenList();
|
||||||
|
|
||||||
|
|
||||||
if (_settings._unusedFunctions)
|
if (_settings._unusedFunctions)
|
||||||
_checkFunctionUsage.parseTokens(_tokenizer);
|
_checkFunctionUsage.parseTokens(_tokenizer);
|
||||||
|
|
||||||
|
|
|
@ -174,6 +174,7 @@ private:
|
||||||
TEST_CASE(dealloc_use_4);
|
TEST_CASE(dealloc_use_4);
|
||||||
TEST_CASE(dealloc_use_5);
|
TEST_CASE(dealloc_use_5);
|
||||||
TEST_CASE(dealloc_use_6);
|
TEST_CASE(dealloc_use_6);
|
||||||
|
TEST_CASE(dealloc_use_7);
|
||||||
|
|
||||||
// free a free'd pointer
|
// free a free'd pointer
|
||||||
TEST_CASE(freefree1);
|
TEST_CASE(freefree1);
|
||||||
|
@ -1728,6 +1729,17 @@ private:
|
||||||
ASSERT_EQUALS(std::string(""), errout.str());
|
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()
|
void freefree1()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue