1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
From: =?utf-8?q?Christian_G=C3=B6ttsche?= <cgzones@googlemail.com>
Date: Fri, 24 Jul 2020 16:40:00 +0200
Subject: chkdirs: free memory on failure
chkdirs.c:182:7: warning: Potential leak of memory pointed to by 'dl'
fprintf(stderr, "lstat(%s/%s): %s\n",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/stdio2.h:113:3: note: expanded from macro 'fprintf'
__fprintf_chk (stream, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__)
^~~~~~~~~~~~~
Last-Updated: 2021-10-10
Forwarded: https://lists.debian.org/debian-security-tools/2021/10/msg00006.html
chkdirs.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/chkdirs.c b/chkdirs.c
index f9bd81c..f5155fa 100644
@@ -103,7 +103,7 @@ int check_dir (char *dir, char *path, int linkcount, int norecurse)
char *curpath, *fullpath;
DIR *dirhandle;
struct dirent *finfo;
- struct dirinfolist *dl, *dptr;
+ struct dirinfolist *dl = NULL, *dptr;
struct stat statinfo;
/* When called recursively, "path" will be the full path of the cwd,
@@ -179,7 +179,6 @@ int check_dir (char *dir, char *path, int linkcount, int norecurse)
}
numdirs = 0;
- dl = (struct dirinfolist *)NULL;
while ((finfo = readdir(dirhandle))) {
if (!strcmp(finfo->d_name, ".") || !strcmp(finfo->d_name, ".."))
continue;
@@ -239,6 +238,11 @@ int check_dir (char *dir, char *path, int linkcount, int norecurse)
curpath, strerror(errno));
exit(255);
}
+ while (dl) {
+ dptr = dl->dil_next;
+ free((void *)dl);
+ dl = dptr;
+ }
free((void *)fullpath);
free((void *)curpath);
return(diff);
|