From f06f6e26e2b84ee8865fe71c67aa6439a0408841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Thu, 3 Apr 2025 15:50:32 +0200 Subject: [PATCH] fix(expand_star): memory leak You have to call closedir(). I also removed the errno checking to make some space, I don't think it is needed when looking at the errors returned by these functions. --- src/subst/wildcard_exp.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/subst/wildcard_exp.c b/src/subst/wildcard_exp.c index ee62d15..4ae2981 100644 --- a/src/subst/wildcard_exp.c +++ b/src/subst/wildcard_exp.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* wildcard_exp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/20 15:01:38 by jguelen #+# #+# */ -/* Updated: 2025/03/21 18:42:04 by jguelen ### ########.fr */ +/* Updated: 2025/04/03 19:58:36 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -104,20 +104,17 @@ static t_wordlist *expand_star_core(t_worddesc *file_pattern) if (current_dir == NULL) return (NULL); file_wordlist = NULL; - errno = 0; new = readdir(current_dir); while (new) { if (fits_pattern(new->d_name, file_pattern)) { if (add_file_to_list(&file_wordlist, new->d_name) == NULL) - return (NULL); + return (closedir(current_dir), NULL); } - errno = 0; new = readdir(current_dir); } - if (errno) - return (wordlist_destroy(file_wordlist), NULL); + closedir(current_dir); if (!file_wordlist) file_wordlist = wordlist_independant_create(file_pattern); return (wordlist_quicksort_full(file_wordlist));