summaryrefslogtreecommitdiffstats
path: root/src/s_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/s_init.c')
-rw-r--r--src/s_init.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/s_init.c b/src/s_init.c
index a572c32..1e86727 100644
--- a/src/s_init.c
+++ b/src/s_init.c
@@ -11,13 +11,13 @@
/* ************************************************************************** */
#include <libft.h>
-#include <stdlib.h>
-#include <unistd.h>
#ifdef __linux__
# include <linux/limits.h>
#else
# include <limits.h>
#endif
+#include <stdlib.h>
+#include <unistd.h>
#include "b_export_next.h"
#include "d_define.h"
@@ -108,21 +108,31 @@ t_msh *s_init_msh(int argc, char *const argv[], char *const envp[])
if ((msh = (t_msh*)malloc(sizeof(t_msh))) == NULL)
return (NULL);
msh->envp = NULL;
+ (void)envp;
if ((msh->envp = s_dupenv(envp)) == NULL)
+ {
+ ft_memdel((void*)&msh);
return (NULL);
+ }
msh->argc = argc - 1;
msh->argv = (char**)argv;
msh->ret = 0;
- init_buptr(msh);
+ m_init_buptr(msh);
s_null_some(msh);
s_set_cwd(cwd, msh);
- if ((msh->cwd = ft_strdup(cwd)) == NULL)
+ if (cwd[0] != C_NUL && (msh->cwd = ft_strdup(cwd)) == NULL)
{
+ ft_delwords(msh->envp);
ft_memdel((void*)&msh);
return (NULL);
}
msh->env_fork_tmp[0][0] = '\0';
- s_inc_shlvl(msh);
+ if (s_inc_shlvl(msh) == 1)
+ {
+ ft_memdel((void*)&msh->cwd);
+ ft_memdel((void*)&msh);
+ return (NULL);
+ }
s_init_sqb_ref_one(msh);
s_init_sqb_ref_two(msh);
s_init_sqb_ref_thr(msh);