summaryrefslogtreecommitdiffstats
path: root/src/u_vars_next.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/u_vars_next.c')
-rw-r--r--src/u_vars_next.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/u_vars_next.c b/src/u_vars_next.c
index 5ffdbb1..28cdd45 100644
--- a/src/u_vars_next.c
+++ b/src/u_vars_next.c
@@ -84,6 +84,7 @@ char u_subst_var_value(const char varname[],
const char newval[],
t_msh *msh)
{
+ size_t i;
long env_line;
char new_line_fmt[ARG_MAX];
@@ -91,10 +92,14 @@ char u_subst_var_value(const char varname[],
{
ft_memdel((void*)&msh->envp[env_line]);
ft_sprintf(new_line_fmt, "%s=%s", varname + 1, newval);
- /* if ((msh->envp[env_line] = (char*)malloc((ft_strlen(new_line_fmt) + 1) * */
- /* sizeof(char))) == NULL) */
- if ((msh->envp[env_line] = NULL) == NULL)
+ if ((msh->envp[env_line] = (char*)malloc((ft_strlen(new_line_fmt) + 1) *
+ sizeof(char))) == NULL)
{
+ i = env_line;
+ while (msh->envp[++i] != NULL)
+ ft_memdel((void*)&msh->envp[i]);
+ ft_delwords(msh->envp);
+ msh->envp = NULL;
return (1);
}
(void)ft_strlcpy(msh->envp[env_line],