posix.cfg: Improved configuration for 'mkstemp()' and added test cases to ensure resource leaks are caught.

This commit is contained in:
orbitcowboy 2019-05-16 15:53:22 +02:00
parent 0144db2490
commit 719eb25ba9
2 changed files with 19 additions and 1 deletions

View File

@ -825,7 +825,6 @@ The obsolescent function 'usleep' is called. POSIX.1-2001 declares usleep() func
<!-- int mkstemp(char *template); -->
<function name="mkstemp">
<noreturn>false</noreturn>
<leak-ignore/>
<returnValue type="int"/>
<arg nr="1">
<not-null/>
@ -4583,6 +4582,7 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
</memory>
<resource>
<alloc init="true">open</alloc>
<alloc init="true">mkstemp</alloc>
<alloc init="true">creat</alloc>
<alloc init="true">openat</alloc>
<alloc init="true">socket</alloc>

View File

@ -134,6 +134,24 @@ void resourceLeak_fdopen(int fd)
// cppcheck-suppress resourceLeak
}
void resourceLeak_mkstemp(char *template)
{
// cppcheck-suppress unreadVariable
int fp = mkstemp(template);
// cppcheck-suppress resourceLeak
}
void no_resourceLeak_mkstemp_01(char *template)
{
int fp = mkstemp(template);
close(fp);
}
int no_resourceLeak_mkstemp_02(char *template)
{
return mkstemp(template);
}
void resourceLeak_fdopendir(int fd)
{
// cppcheck-suppress unreadVariable