Skip to content

Commit 516d0aa

Browse files
committed
fixed hash leak and all cd leaks
1 parent b60ee69 commit 516d0aa

File tree

10 files changed

+49
-20
lines changed

10 files changed

+49
-20
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ $(NAME): $(OBJECTS_PREFIXED) $(LIBFT)
9595
leak: #only use to check leak with valgrind
9696
@echo "leak"
9797
@make re
98-
@valgrind --leak-check=full --tool=memcheck ./$(NAME)
98+
@valgrind --leak-check=full --show-leak-kinds=all --suppressions=valgrind_filter.supp --tool=memcheck ./$(NAME)
9999

100100
all: $(NAME)
101101
@make all -C $(LIBDIR)

include/minishell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,5 +190,7 @@ void free_loop(t_minishell *msh);
190190
void ft_free_hash(t_hash_table *table);
191191
void ft_command_table_free(t_minishell *msh);
192192
bool is_case_alph(char str);
193+
void free_2d_array(char **array);
194+
void ft_free_prompt(t_minishell *msh);
193195

194196
#endif

src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ bool check_valid_line(char *str)
4848
static void minishill_start(t_minishell *msh, char **env)
4949
{
5050
msh->env_table = init_table(env);
51-
msh->env = env2d(msh->env_table);
51+
//print_hash(msh->env_table);
52+
//printf("%s",msh->env[0]);
5253
while (1)
5354
{
5455
read_line(msh);

src/tools/builtins/ft_exit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,7 @@ void ft_exit(t_minishell *msh, int i)
5151
exit(2);
5252
}
5353
ft_with_arg(msh, msh->cmd_table[i]->exec_table);
54+
ft_free_prompt(msh);
55+
ft_command_table_free(msh);
5456
ft_free_minishell(msh);
5557
}

src/tools/exec/execute.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void execute(t_minishell *msh, int i)
5252
}
5353
else
5454
{
55-
execve(get_path(msh, i), msh->cmd_table[i]->exec_table, msh->env);
55+
execve(get_path(msh, i), msh->cmd_table[i]->exec_table, NULL);
5656
error_message(msh, "NOT FOUND", 127);
5757
exit(127);
5858
}
@@ -76,8 +76,7 @@ void init_execute(t_minishell *msh)
7676
i = 0;
7777
if (msh->command_count == 1)
7878
{
79-
if (!ft_strncmp(msh->cmd_table[i]->exec_table[0], "cd", 3) || \
80-
!ft_strncmp(msh->cmd_table[i]->exec_table[0], "exit", 5))
79+
if (msh->cmd_table[i]->command_type == BUILTIN)
8180
execute_builtin(msh, i);
8281
else
8382
execute(msh, 0);

src/tools/hash/remove_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ void remove_hash(t_minishell *msh, char *key)
2323
free(msh->env_table->table[i]->value);
2424
msh->env_table->table[i] = NULL;
2525
}
26-
msh->env = env2d(msh->env_table);
26+
//msh->env = env2d(msh->env_table);
2727
}

src/tools/hash/update_hash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ void update_hash(t_minishell *msh, char *key, char *value)
4141
msh->env_table->table[i]->value = ft_strdup(value);
4242
msh->env_table->count++;
4343
}
44-
free(msh->env);
45-
msh->env = env2d(msh->env_table);
44+
//free_2d_array(msh->env);
45+
//msh->env = env2d(msh->env_table);
4646
}

src/tools/tokenizer/tokenizer_tools.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
/* ::: :::::::: */
44
/* tokenizer_tools.c :+: :+: :+: */
55
/* +:+ +:+ +:+ */
6-
/* By: oal-tena <oal-tena@student.42.fr> +#+ +:+ +#+ */
6+
/* By: Dokcer <Dokcer@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/06/22 04:59:25 by oal-tena #+# #+# */
9-
/* Updated: 2022/06/22 07:29:52 by oal-tena ### ########.fr */
9+
/* Updated: 2022/07/13 13:58:43 by Dokcer ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

src/utils/ft_free.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: Dokcer <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/04/24 12:39:16 by oal-tena #+# #+# */
9-
/* Updated: 2022/07/13 11:47:39 by Dokcer ### ########.fr */
9+
/* Updated: 2022/07/13 14:10:02 by Dokcer ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -15,20 +15,20 @@
1515
void ft_free_hash(t_hash_table *table)
1616
{
1717
unsigned int i;
18-
unsigned long _hash;
1918

2019
i = 0;
21-
while (table->table[i])
20+
while (i < table->size)
2221
{
23-
_hash = hash(table->table[i]->key, table->size);
24-
if (table->table[_hash])
22+
if (table->table[i])
2523
{
26-
free(table->table[_hash]->key);
27-
free(table->table[_hash]->value);
28-
free(table->table[_hash]);
24+
free(table->table[i]->key);
25+
free(table->table[i]->value);
26+
free(table->table[i]);
2927
}
3028
i++;
3129
}
30+
free(table->table);
31+
free(table);
3232
}
3333

3434
void ft_free_prompt(t_minishell *msh)
@@ -42,8 +42,18 @@ void free_2d_array(char **array)
4242
int i;
4343

4444
i = 0;
45-
while (array && array[i])
46-
free(array[i++]);
45+
if (array)
46+
{
47+
while (1)
48+
{
49+
if (array[i])
50+
{
51+
free(array[i++]);
52+
}
53+
else
54+
break ;
55+
}
56+
}
4757
free(array);
4858
}
4959

@@ -97,5 +107,6 @@ void ft_command_table_free(t_minishell *msh)
97107
void ft_free_minishell(t_minishell *minishell)
98108
{
99109
ft_free_hash(minishell->env_table);
110+
//free_2d_array(minishell->env);
100111
exit(minishell->exit_status);
101112
}

valgrind_filter.supp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
readline
3+
Memcheck:Leak
4+
fun:*
5+
...
6+
fun:readline
7+
}
8+
{
9+
add_history
10+
Memcheck:Leak
11+
fun:*
12+
...
13+
fun:add_history
14+
}

0 commit comments

Comments
 (0)