searching solution for invalid free in readline.
This commit is contained in:
@@ -25,7 +25,7 @@ int builtin_export(int argc, char *argv[], t_all *c)
|
||||
if (environ[env_position] == '\0')
|
||||
environ = ft_resize_2d_arr(environ, 1);
|
||||
environ[env_position] = ft_strdup(argv[1]);
|
||||
if (!ft_strncmp(var[0], "PATH", 4 + 1))
|
||||
if (!ft_strncmp(var[0], "PATH", 4 + 1)) // TODO : NON. Ce n'est pas la fin de la string donc "strlen() + 1" n'est pas adapté
|
||||
c->path = retrieve_path();
|
||||
// free var
|
||||
return (0);
|
||||
|
||||
27
srcs/free.c
27
srcs/free.c
@@ -6,18 +6,41 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/10 23:53:17 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/26 21:51:44 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/27 23:50:15 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
// WIP : un peu zob. Previent les invalid free de readline, mais peut leak si "LINES" ou "COLUMNS" sont redefini avec export
|
||||
void ft_free_2d_arr_ENVIRON(void *ptr)
|
||||
{
|
||||
unsigned int i;
|
||||
char **arr;
|
||||
|
||||
if (!ptr)
|
||||
return ;
|
||||
arr = (char **)ptr;
|
||||
i = 0;
|
||||
while (arr[i])
|
||||
{
|
||||
if (ft_strncmp(arr[i], "LINES=", 5 + 1) != 0 && ft_strncmp(arr[i], "COLUMNS=", 7 + 1) != 0)
|
||||
free(arr[i]);
|
||||
i++;
|
||||
}
|
||||
free(arr);
|
||||
}
|
||||
|
||||
int free_exit(t_all *c, int exit_status)
|
||||
{
|
||||
free(c->prompt_base);
|
||||
free(c->prompt);
|
||||
ft_lstclear((t_list **)&c->token_list, free);
|
||||
ft_free_2d_arr(environ);
|
||||
//ft_free_2d_arr(environ);
|
||||
ft_free_2d_arr_ENVIRON(environ);
|
||||
free(g_ori_environ);
|
||||
//environ = g_ori_environ; // WIP free test
|
||||
environ = NULL; // WIP free test
|
||||
ft_free_2d_arr(c->path);
|
||||
free_pipeline(&c->cmd_arr);
|
||||
//if (c->termios_changed)
|
||||
|
||||
19
srcs/init.c
19
srcs/init.c
@@ -6,26 +6,25 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/08 09:22:12 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/26 21:51:40 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/27 23:50:06 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
static char *init_prompt_base(void);
|
||||
// pas static si utilisee par cd
|
||||
//static char *init_prompt(char *prompt_base);
|
||||
char *init_prompt(char *prompt_base);
|
||||
|
||||
//int init(t_all *c, char *envp[])
|
||||
int init(t_all *c)
|
||||
{
|
||||
ft_bzero(c, sizeof (*c));
|
||||
environ = ft_dup_2d_arr(environ, (t_dup_f)ft_strdup);
|
||||
g_ori_environ = environ; // Wip free test
|
||||
//environ = ft_resize_2d_arr(environ, 0); // WIP free test
|
||||
if (!environ)
|
||||
return (ft_reti_perror(0, "ft_dup_2d_char_arr(environ) error"));
|
||||
return (ft_reti_perror(0, "ft_dup_2d_arr(environ) error"));
|
||||
//environ = NULL; // WIP free test
|
||||
//print_matrix(c->envp, "\n --- \n"); // TEST WIP
|
||||
c->path = retrieve_path(environ); // No return check. Its intended. PATH is optional
|
||||
c->path = retrieve_path(); // No return check. Its intended. PATH is optional
|
||||
c->prompt_base = init_prompt_base();
|
||||
if (!c->prompt_base)
|
||||
return (ft_reti_perror(0, "init_prompt_base() error"));
|
||||
@@ -37,14 +36,11 @@ int init(t_all *c)
|
||||
}
|
||||
|
||||
// done : TODO : Un appel à builtin_export() modifiant $PATH doit aussi entrainer un appel à "c->path = retrieve_path()"
|
||||
// changer le prototype si utilise pas envp
|
||||
char **retrieve_path(char *envp[])
|
||||
char **retrieve_path(void)
|
||||
{
|
||||
char *path;
|
||||
char **path_split;
|
||||
|
||||
(void)envp;
|
||||
//path = search_env_var(envp, "PATH"); // A reprendre du projet pipex si besoin de remplacer getenv()
|
||||
path = getenv("PATH");
|
||||
if (!path)
|
||||
return (ft_retp_print(NULL, "minishell: Warning, $PATH not set\n", 2));
|
||||
@@ -74,7 +70,6 @@ static char *init_prompt_base(void) // WIP, error return TODO
|
||||
return (prompt_base);
|
||||
}
|
||||
|
||||
//static char *init_prompt(char *prompt_base) // WIP, error return TODO
|
||||
char *init_prompt(char *prompt_base) // WIP, error return TODO
|
||||
{
|
||||
char *prompt;
|
||||
|
||||
Reference in New Issue
Block a user