Fixed #1416 (false negative resource leak when calling fdopen)
This commit is contained in:
parent
36f4431481
commit
44a66e6a5a
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
<function name="popen"><noreturn>false</noreturn><arg nr="1"><not-null/><not-uninit/></arg><arg nr="2"><not-null/><not-uninit/></arg></function>
|
<function name="popen"><noreturn>false</noreturn><arg nr="1"><not-null/><not-uninit/></arg><arg nr="2"><not-null/><not-uninit/></arg></function>
|
||||||
<function name="pclose"><noreturn>false</noreturn><arg nr="1"><not-null/><not-uninit/></arg></function>
|
<function name="pclose"><noreturn>false</noreturn><arg nr="1"><not-null/><not-uninit/></arg></function>
|
||||||
|
<function name="fdopen"><noreturn>false</noreturn><arg nr="1"><not-null/><not-uninit/></arg></function>
|
||||||
|
|
||||||
<resource>
|
<resource>
|
||||||
<dealloc>close</dealloc>
|
<dealloc>close</dealloc>
|
||||||
|
@ -46,9 +46,13 @@
|
||||||
<alloc init="true">fdopendir</alloc>
|
<alloc init="true">fdopendir</alloc>
|
||||||
</resource>
|
</resource>
|
||||||
|
|
||||||
|
<resource>
|
||||||
|
<dealloc>fclose</dealloc>
|
||||||
|
<alloc init="true">fdopen</alloc>
|
||||||
|
</resource>
|
||||||
|
|
||||||
<resource>
|
<resource>
|
||||||
<dealloc>pclose</dealloc>
|
<dealloc>pclose</dealloc>
|
||||||
<alloc init="true">popen</alloc>
|
<alloc init="true">popen</alloc>
|
||||||
</resource>
|
</resource>
|
||||||
</def>
|
</def>
|
||||||
|
|
||||||
|
|
|
@ -184,6 +184,8 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
|
||||||
if (alloctype > 0) {
|
if (alloctype > 0) {
|
||||||
if (alloctype == settings1->library.dealloc("free"))
|
if (alloctype == settings1->library.dealloc("free"))
|
||||||
return Malloc;
|
return Malloc;
|
||||||
|
if (alloctype == settings1->library.dealloc("fclose"))
|
||||||
|
return File;
|
||||||
return Library::ismemory(alloctype) ? OtherMem : OtherRes;
|
return Library::ismemory(alloctype) ? OtherMem : OtherRes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -612,7 +614,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
|
||||||
if (noreturn.find(tok->str()) != noreturn.end() && tok->strAt(-1) != "=")
|
if (noreturn.find(tok->str()) != noreturn.end() && tok->strAt(-1) != "=")
|
||||||
return "exit";
|
return "exit";
|
||||||
|
|
||||||
if (varid > 0 && (getAllocationType(tok, varid) != No || getReallocationType(tok, varid) != No || getDeallocationType(tok, varid) != No))
|
if (varid > 0 && (getReallocationType(tok, varid) != No || getDeallocationType(tok, varid) != No))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (callstack.size() > 2)
|
if (callstack.size() > 2)
|
||||||
|
|
|
@ -330,7 +330,6 @@ private:
|
||||||
TEST_CASE(getc_function);
|
TEST_CASE(getc_function);
|
||||||
|
|
||||||
TEST_CASE(open_function);
|
TEST_CASE(open_function);
|
||||||
TEST_CASE(open_fdopen);
|
|
||||||
TEST_CASE(creat_function);
|
TEST_CASE(creat_function);
|
||||||
TEST_CASE(close_function);
|
TEST_CASE(close_function);
|
||||||
TEST_CASE(fd_functions);
|
TEST_CASE(fd_functions);
|
||||||
|
@ -3876,19 +3875,6 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void open_fdopen() {
|
|
||||||
// Ticket #2830
|
|
||||||
Settings settings;
|
|
||||||
settings.standards.posix = true;
|
|
||||||
check("void f(const char *path)\n"
|
|
||||||
"{\n"
|
|
||||||
" int fd = open(path, O_RDONLY);\n"
|
|
||||||
" FILE *f = fdopen(fd, x);\n"
|
|
||||||
" fclose(f);\n"
|
|
||||||
"}", &settings);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void creat_function() {
|
void creat_function() {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.standards.posix = true;
|
settings.standards.posix = true;
|
||||||
|
@ -4267,6 +4253,20 @@ private:
|
||||||
check(code2, &settings);
|
check(code2, &settings);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// Ticket #2830
|
||||||
|
check("void f(const char *path) {\n"
|
||||||
|
" int fd = open(path, O_RDONLY);\n"
|
||||||
|
" FILE *f = fdopen(fd, x);\n"
|
||||||
|
" fclose(f);\n"
|
||||||
|
"}", &settings);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// Ticket #1416
|
||||||
|
check("void f(void) {\n"
|
||||||
|
" FILE *f = fdopen(0, \"r\");\n"
|
||||||
|
"}", &settings);
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (error) Resource leak: f\n", errout.str());
|
||||||
|
|
||||||
LOAD_LIB_2(settings.library, "gtk.cfg");
|
LOAD_LIB_2(settings.library, "gtk.cfg");
|
||||||
|
|
||||||
check("void f(char *a) {\n"
|
check("void f(char *a) {\n"
|
||||||
|
|
Loading…
Reference in New Issue