retrieve_path() leak fixed

This commit is contained in:
lperrey
2021-12-22 19:34:21 +01:00
parent 9bffb99b30
commit 69adb1cf2f
5 changed files with 21 additions and 13 deletions

View File

@@ -6,22 +6,30 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/08 09:22:12 by lperrey #+# #+# */
/* Updated: 2021/12/08 06:27:23 by lperrey ### ########.fr */
/* Updated: 2021/12/22 19:28:49 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char **retrieve_path(void)
#define WARNING_PATH "Warning, $PATH not set\n"
int retrieve_path(char **path_stock[])
{
char *path;
char **path_split;
path = getenv("PATH");
if (!path)
return (ft_retp_print(NULL, "minishell: Warning, $PATH not set\n", 2));
{
ft_free_2d_arr(*path_stock);
*path_stock = NULL;
return (shell_error(WARNING_PATH, "", "", 0));
}
path_split = ft_split(path, ':');
if (!path_split)
return (ft_retp_perror(NULL, "retrieve_path()"));
return (path_split);
return (ft_reti_perror(-1, "retrieve_path()"));
ft_free_2d_arr(*path_stock);
*path_stock = path_split;
return (1);
}