-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_clean.c
89 lines (81 loc) · 1.35 KB
/
ft_clean.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "ft_minishell.h"
int rebut_utils(t_command_and_flag *command)
{
t_command_and_flag *tmp;
int i;
while (command)
{
free(command->command_and_flags);
free(command->command);
free(command->flags);
i = 1;
if (command->array_flags != NULL)
{
while (command->array_flags[i])
{
free(command->array_flags[i]);
i++;
}
free(command->array_flags);
}
tmp = command->next;
free(command);
command = tmp;
}
return (0);
}
void rebut(t_minishell *all_command)
{
int i;
t_command_and_flag *command;
t_command_and_flag *tmp;
all_command->onecovkey = 0;
all_command->doublecovkey = 0;
command = all_command->head;
rebut_utils(command);
if (all_command->path != NULL)
{
i = 0;
while (all_command->path[i])
{
free(all_command->path[i]);
i++;
}
free(all_command->path);
}
all_command->head = NULL;
}
int clear_malloc_utils(t_env *env)
{
int i;
i = 0;
if (env->env_lvl != NULL)
{
while (env->env_lvl[i])
{
free(env->env_lvl[i]);
i++;
}
free(env->env_lvl);
}
return (0);
}
void clear_malloc(t_minishell *all_command, t_env *env)
{
int i;
i = 0;
free(all_command->file_history);
while (env->env[i])
{
free(env->env[i]);
free(env->keys[i]);
free(env->values[i]);
i++;
}
i = 0;
free(env->env);
free(env->keys);
free(env->values);
clear_malloc_utils(env);
free(env);
}