diff --git a/cfg/posix.cfg b/cfg/posix.cfg
index 075fbab13..a0a80b8f8 100644
--- a/cfg/posix.cfg
+++ b/cfg/posix.cfg
@@ -4026,6 +4026,32 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
+
+
+
+
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -4863,6 +4889,10 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
posix_memalign
free
+
+ scandir
+ free
+
strdup
strndup
diff --git a/test/cfg/posix.c b/test/cfg/posix.c
index f22406b91..3b4338e40 100644
--- a/test/cfg/posix.c
+++ b/test/cfg/posix.c
@@ -21,6 +21,38 @@
#include
#include
+void memleak_scandir(void)
+{
+ struct dirent **namelist;
+ int n = scandir(".", &namelist, NULL, alphasort);
+ if (n == -1) {
+ return;
+ }
+
+ // http://man7.org/linux/man-pages/man3/scandir.3.html
+ /* The scandir() function scans the directory dirp, calling filter() on
+ each directory entry. Entries for which filter() returns nonzero are
+ stored in strings allocated via malloc(3), sorted using qsort(3) with
+ the comparison function compar(), and collected in array namelist
+ which is allocated via malloc(3). If filter is NULL, all entries are
+ selected.*/
+
+ // TODO: cppcheck-suppress memleak
+}
+
+void no_memleak_scandir(void)
+{
+ struct dirent **namelist;
+ int n = scandir(".", &namelist, NULL, alphasort);
+ if (n == -1) {
+ return;
+ }
+ while (n--) {
+ free(namelist[n]);
+ }
+ free(namelist);
+}
+
void validCode()
{
void *ptr;