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.
This commit is contained in:
Khaïs COLIN 2025-04-03 15:50:32 +02:00
parent 32e3976774
commit f06f6e26e2
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* wildcard_exp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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));