diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-24 19:35:05 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-24 19:35:05 +0200 |
commit | 418c6adb9b6c60dce662778257abb93c216da891 (patch) | |
tree | 62b6854c3b221a9e8661c968d9a32294f7290989 /src | |
parent | .gitignore update (diff) | |
download | 42-minishell-418c6adb9b6c60dce662778257abb93c216da891.tar.gz 42-minishell-418c6adb9b6c60dce662778257abb93c216da891.tar.bz2 42-minishell-418c6adb9b6c60dce662778257abb93c216da891.tar.xz 42-minishell-418c6adb9b6c60dce662778257abb93c216da891.tar.zst 42-minishell-418c6adb9b6c60dce662778257abb93c216da891.zip |
Freed leaks, fix in progress
Diffstat (limited to 'src')
-rw-r--r-- | src/b_cd.c | 25 | ||||
-rw-r--r-- | src/b_export_next.c | 1 |
2 files changed, 14 insertions, 12 deletions
@@ -73,7 +73,7 @@ static void { if (ft_strncmp(splited[i], "..", 3) == 0) { - j = ft_strlen(repath); + j = (repath[0] == '\0') ? (0) : (ft_strlen(repath)); while (repath[j] != '/' && j > 0) j--; repath[j] = '\0'; @@ -94,27 +94,28 @@ static void static void b_upgrade_pwd(const char path[], t_msh *msh) { - char *tmp; char **splited; char repath[262144]; char fmt[262144]; b_set_oldpwd(msh); + splited = NULL; repath[0] = '\0'; if (path[0] != '/') - ft_memcpy(repath, msh->cwd, ft_strlen(msh->cwd)); - if ((splited = ft_split(path, '/')) == NULL) + ft_memcpy(repath, msh->cwd, (ft_strlen(msh->cwd) + 1) * sizeof(char)); + if (path[0] == '/' && path[1] == '\0') + ft_memcpy(repath, "/", 2 * sizeof(char)); + else if ((splited = ft_split(path, '/')) == NULL) f_alloc_and_destroy_msh(msh); - b_fill_repath(repath, splited); - repath[0] = (repath[0] == '\0') ? '/' : repath[0]; - ft_delwords(splited); - if ((tmp = u_get_var_value("$PWD", msh)) != NULL) - u_subst_var_value("$PWD", repath, msh); - else + if (splited != NULL) { - ft_sprintf(fmt, "%s=%s", "PWD", repath); - b_export_with_equals(fmt, msh); + b_fill_repath(repath, splited); + ft_delwords(splited); } + repath[0] = (repath[0] == '\0') ? '/' : repath[0]; + ft_printf("[%s]\n", repath); + ft_sprintf(fmt, "%s=%s", "PWD", repath); + b_export_with_equals(fmt, msh); ft_memdel((void*)&msh->cwd); if ((msh->cwd = ft_strdup(repath)) == NULL) f_alloc_and_destroy_msh(msh); diff --git a/src/b_export_next.c b/src/b_export_next.c index 90a4820..c46389a 100644 --- a/src/b_export_next.c +++ b/src/b_export_next.c @@ -56,6 +56,7 @@ static int64_t { if (ft_strncmp(varname, env_dup[i], ft_strlen(env_dup[i]) + 1) == 0) { + ft_delwords(env_dup); return (i); } i++; |