retrieve_path() leak fixed
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */
|
/* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/12/22 13:50:04 by lperrey ### ########.fr */
|
/* Updated: 2021/12/22 19:28:07 by lperrey ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ extern char **environ;
|
|||||||
// Init
|
// Init
|
||||||
int init(t_all *c, char *argv[]);
|
int init(t_all *c, char *argv[]);
|
||||||
char *update_prompt(char *prompt_base);
|
char *update_prompt(char *prompt_base);
|
||||||
char **retrieve_path(void);
|
int retrieve_path(char **path_stock[]);
|
||||||
void set_signals_behaviour(void);
|
void set_signals_behaviour(void);
|
||||||
|
|
||||||
// Shell modes
|
// Shell modes
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/12/03 13:36:54 by lperrey #+# #+# */
|
/* Created: 2021/12/03 13:36:54 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/12/21 22:41:14 by lperrey ### ########.fr */
|
/* Updated: 2021/12/22 19:23:41 by lperrey ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ int builtin_export(int argc, char *argv[], t_all *c)
|
|||||||
else if (ret == ERR_ID)
|
else if (ret == ERR_ID)
|
||||||
exit_value = EXIT_FAILURE;
|
exit_value = EXIT_FAILURE;
|
||||||
if (ft_strncmp(argv[i], "PATH=", 5) == 0)
|
if (ft_strncmp(argv[i], "PATH=", 5) == 0)
|
||||||
c->path = retrieve_path();
|
retrieve_path(&c->path);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (exit_value);
|
return (exit_value);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/12/05 17:05:05 by lperrey #+# #+# */
|
/* Created: 2021/12/05 17:05:05 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/12/18 13:41:15 by lperrey ### ########.fr */
|
/* Updated: 2021/12/22 19:23:50 by lperrey ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ int builtin_unset(int argc, char *argv[], t_all *c)
|
|||||||
if (unset_env_var(argv[i]) == EXIT_FAILURE)
|
if (unset_env_var(argv[i]) == EXIT_FAILURE)
|
||||||
exit_value = EXIT_FAILURE;
|
exit_value = EXIT_FAILURE;
|
||||||
if (ft_strncmp(argv[i], "PATH", 4 + 1) == 0)
|
if (ft_strncmp(argv[i], "PATH", 4 + 1) == 0)
|
||||||
c->path = retrieve_path();
|
retrieve_path(&c->path);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (exit_value);
|
return (exit_value);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/08 09:22:12 by lperrey #+# #+# */
|
/* Created: 2021/10/08 09:22:12 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/12/20 22:26:05 by lperrey ### ########.fr */
|
/* Updated: 2021/12/22 19:24:04 by lperrey ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ int init(t_all *c, char *argv[])
|
|||||||
environ = ft_dup_2d_arr(environ, (t_dup_f)ft_strdup);
|
environ = ft_dup_2d_arr(environ, (t_dup_f)ft_strdup);
|
||||||
if (!environ)
|
if (!environ)
|
||||||
return (ft_reti_perror(0, "ft_dup_2d_arr(environ)"));
|
return (ft_reti_perror(0, "ft_dup_2d_arr(environ)"));
|
||||||
c->path = retrieve_path();
|
retrieve_path(&c->path);
|
||||||
if (!init_shlvl())
|
if (!init_shlvl())
|
||||||
return (ft_reti_perror(0, "init_shlvl()"));
|
return (ft_reti_perror(0, "init_shlvl()"));
|
||||||
open_script_file(c, argv);
|
open_script_file(c, argv);
|
||||||
|
|||||||
@@ -6,22 +6,30 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/08 09:22:12 by lperrey #+# #+# */
|
/* 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"
|
#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;
|
||||||
char **path_split;
|
char **path_split;
|
||||||
|
|
||||||
path = getenv("PATH");
|
path = getenv("PATH");
|
||||||
if (!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, ':');
|
path_split = ft_split(path, ':');
|
||||||
if (!path_split)
|
if (!path_split)
|
||||||
return (ft_retp_perror(NULL, "retrieve_path()"));
|
return (ft_reti_perror(-1, "retrieve_path()"));
|
||||||
return (path_split);
|
ft_free_2d_arr(*path_stock);
|
||||||
|
*path_stock = path_split;
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user