From 3751721fbb2b72cf99dff3755249357ef5372205 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sun, 29 Jul 2001 12:01:09 -0400 Subject: [PATCH] finddev.c (scan_dir): Fix memory leak; we weren't calling closedir() when exiting the function in all cases. --- lib/ext2fs/ChangeLog | 5 +++++ lib/ext2fs/finddev.c | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 9005688..0c28ed4 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,8 @@ +2001-07-29 Theodore Tso + + * finddev.c (scan_dir): Fix memory leak; we weren't calling + closedir() when exiting the function in all cases. + 2001-07-27 Theodore Tso * mkjournal.c (ext2fs_create_journal_superblock): Set the first diff --git a/lib/ext2fs/finddev.c b/lib/ext2fs/finddev.c index 5d85324..2e9d70a 100644 --- a/lib/ext2fs/finddev.c +++ b/lib/ext2fs/finddev.c @@ -101,15 +101,18 @@ static int scan_dir(char *dirname, dev_t device, struct dir_list **list, add_to_dirlist(path, list); if (S_ISBLK(st.st_mode) && st.st_rdev == device) { cp = malloc(strlen(path)+1); - if (!cp) + if (!cp) { + closedir(dir); return ENOMEM; + } strcpy(cp, path); *ret_path = cp; - return 0; + goto success; } skip_to_next: dp = readdir(dir); } +success: closedir(dir); return 0; } -- 1.8.3.1