From 4e4fd52670a5730afa676102cb5e3fc81c78b42f Mon Sep 17 00:00:00 2001 From: PrStein Date: Sat, 16 Apr 2022 19:50:11 +0200 Subject: [PATCH] leaks home and leaks export --- srcs/built_in/cd.c | 3 ++- srcs/built_in/export2.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/srcs/built_in/cd.c b/srcs/built_in/cd.c index 1b45d2e..21a7424 100644 --- a/srcs/built_in/cd.c +++ b/srcs/built_in/cd.c @@ -138,7 +138,8 @@ void check_home(t_s_cmd *cmd, char *p) if (chdir(p) == 0) if (find_it(cmd->big_cmd->env, "PWD") != -1) { - cmd->big_cmd->env[old_pwd] = ft_strjoin("OLD", cmd->big_cmd->env[pwd]); + if (find_it(cmd->big_cmd->env, "OLDPWD") != -1) + cmd->big_cmd->env[old_pwd] = ft_strjoin("OLD", cmd->big_cmd->env[pwd]); cmd->big_cmd->env[pwd] = ft_strjoin("PWD=", p); } free(p); diff --git a/srcs/built_in/export2.c b/srcs/built_in/export2.c index c71a63c..ddb23da 100644 --- a/srcs/built_in/export2.c +++ b/srcs/built_in/export2.c @@ -49,7 +49,9 @@ void print_export(char *tmp) i = 0; str1 = ft_substr(tmp, 0, find_len(tmp, i, '=')); i = find_len(tmp, 0, '=') + 1; - str2 = ft_substr(tmp, i, find_len(tmp, i, '\0')); + str2 = ft_substr(tmp, i, ft_strlen(tmp)); + + // str2 = ft_substr(tmp, i, find_len(tmp, i, '\0')); printf("declare -x %s", str1); if (next_space(str2, 0) != '\0') printf("=\"%s\"", str2);