Fixed ticket #464 (resource leak not detected when getc is used on the file handle)
http://sourceforge.net/apps/trac/cppcheck/ticket/464
This commit is contained in:
parent
53c120c701
commit
a0a526a205
|
@ -428,7 +428,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
|
|||
return 0;
|
||||
|
||||
// I/O functions that are not allocating nor deallocating memory..
|
||||
if (Token::Match(tok, "fgets|fgetc|fputs|fputc|feof|ferror|clearerr|printf|fprintf") ||
|
||||
if (Token::Match(tok, "fgets|fgetc|getc|fputs|fputc|feof|ferror|clearerr|printf|fprintf") ||
|
||||
Token::Match(tok, "fread|fwrite|fflush|fseek|fseeko|ftell|ftello|fsetpos|fgetpos") ||
|
||||
Token::Match(tok, "setvbuf|setbuf|setbuffer|setlinebuf|rewind"))
|
||||
return 0;
|
||||
|
|
|
@ -277,6 +277,7 @@ private:
|
|||
TEST_CASE(tmpfile_function);
|
||||
TEST_CASE(fcloseall_function);
|
||||
TEST_CASE(file_functions);
|
||||
TEST_CASE(getc_function);
|
||||
|
||||
TEST_CASE(open_function);
|
||||
TEST_CASE(creat_function);
|
||||
|
@ -2403,6 +2404,29 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:22]: (error) Resource leak: f\n", errout.str());
|
||||
}
|
||||
|
||||
void getc_function() {
|
||||
{
|
||||
check("void f()\n"
|
||||
"{"
|
||||
" int c;\n"
|
||||
" FILE *fin1a = fopen (\"FILE.txt\", \"r\");\n"
|
||||
" while ( (c = getc (fin1a)) != EOF)\n"
|
||||
" { }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:6]: (error) Resource leak: fin1a\n", errout.str());
|
||||
}
|
||||
|
||||
{
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" int c;\n"
|
||||
" FILE *fin1b = fopen(\"FILE.txt\", \"r\");\n"
|
||||
" c = getc(fin1b);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:6]: (error) Resource leak: fin1b\n", errout.str());
|
||||
}
|
||||
}
|
||||
|
||||
void pointer_to_pointer()
|
||||
{
|
||||
check("void f(char **data)\n"
|
||||
|
|
Loading…
Reference in New Issue