-
Notifications
You must be signed in to change notification settings - Fork 1
/
free.c
87 lines (78 loc) · 2.03 KB
/
free.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: itulgar < [email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/08 17:47:51 by itulgar #+# #+# */
/* Updated: 2024/11/07 18:59:25 by itulgar ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static void free_envp_list(t_mlist *envp_list)
{
t_mlist *temp;
while (envp_list)
{
temp = envp_list->next;
free(envp_list->content);
free(envp_list->key);
free(envp_list);
envp_list = temp;
}
}
void free_array(char **tmp)
{
int i;
i = 0;
while (tmp && tmp[i])
{
free(tmp[i]);
i++;
}
if (tmp)
free(tmp);
}
void free_parser_input(t_program *program)
{
int i;
int j;
i = 0;
j = 0;
if (!program->parser_input)
return ;
while (program->parser_input[i])
{
j = 0;
while (program->parser_input[i][j])
{
if (program->parser_input[i][j]->cmd)
free(program->parser_input[i][j]->cmd);
free(program->parser_input[i][j]);
j++;
}
free(program->parser_input[i]);
i++;
}
free(program->parser_input);
}
void free_program(t_program *program)
{
if (!program)
return ;
if (program->input)
free(program->input);
if (program->parser_input)
free_parser_input(program);
if (program->envp_list)
free_envp_list(program->envp_list);
free(program);
}
void dolar_free(char *env_str, char *after_dolar)
{
if (env_str != NULL && env_str[0] != '\0')
free(env_str);
if (after_dolar)
free(after_dolar);
}