#include <linux/kernel.h>
 #include <linux/string.h>
 #include <subcmd/exec-cmd.h>
+#include <linux/zalloc.h>
 
 static bool dont_fork;
 
 {
        struct dirent **entlist;
        struct dirent *ent;
-       int n_dirs;
+       int n_dirs, e;
        char path_dir[PATH_MAX];
        const char *path = shell_tests__dir(path_dir, sizeof(path_dir));
        int width = 0;
                }
        }
 
+       for (e = 0; e < n_dirs; e++)
+               zfree(&entlist[e]);
        free(entlist);
-
        return width;
 }
 
 {
        struct dirent **entlist;
        struct dirent *ent;
-       int n_dirs;
+       int n_dirs, e;
        char path_dir[PATH_MAX];
        struct shell_test st = {
                .dir = shell_tests__dir(path_dir, sizeof(path_dir)),
                test_and_print(&test, false, -1);
        }
 
+       for (e = 0; e < n_dirs; e++)
+               zfree(&entlist[e]);
        free(entlist);
        return 0;
 }
 {
        struct dirent **entlist;
        struct dirent *ent;
-       int n_dirs;
+       int n_dirs, e;
        char path_dir[PATH_MAX];
        const char *path = shell_tests__dir(path_dir, sizeof(path_dir));
 
                        continue;
 
                pr_info("%2d: %s\n", i, t.desc);
+
        }
 
+       for (e = 0; e < n_dirs; e++)
+               zfree(&entlist[e]);
        free(entlist);
        return 0;
 }