From 719eb25ba9f53ed0c3b8115bc0497585004c6012 Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Thu, 16 May 2019 15:53:22 +0200 Subject: [PATCH] posix.cfg: Improved configuration for 'mkstemp()' and added test cases to ensure resource leaks are caught. --- cfg/posix.cfg | 2 +- test/cfg/posix.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cfg/posix.cfg b/cfg/posix.cfg index b659965ca..5dd716aca 100644 --- a/cfg/posix.cfg +++ b/cfg/posix.cfg @@ -825,7 +825,6 @@ The obsolescent function 'usleep' is called. POSIX.1-2001 declares usleep() func false - @@ -4583,6 +4582,7 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s open + mkstemp creat openat socket diff --git a/test/cfg/posix.c b/test/cfg/posix.c index 942dff08f..ed348f09b 100644 --- a/test/cfg/posix.c +++ b/test/cfg/posix.c @@ -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