-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfree2.c
More file actions
executable file
·67 lines (62 loc) · 1.99 KB
/
free2.c
File metadata and controls
executable file
·67 lines (62 loc) · 1.99 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hkonte <hkonte@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/29 13:13:55 by hkonte #+# #+# */
/* Updated: 2024/11/29 13:14:27 by hkonte ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int free_execve(t_main **main)
{
delete_tube(*main);
free_envp(&(*main)->envp);
if ((*main)->cmd_info && (*main)->cmd_info->cmd_path)
{
free((*main)->cmd_info->cmd_path);
(*main)->cmd_info->cmd_path = NULL;
}
if ((*main)->pids)
free((*main)->pids);
free((*main)->tube);
free_all_cmd_info(main);
free((*main)->str_envp);
free_tokens(&(*main)->tokens);
if ((*main)->cmds_paths)
{
auto int i = 0;
while ((*main)->cmds_paths->paths && (*main)->cmds_paths->paths[i])
free((*main)->cmds_paths->paths[i++]);
free((*main)->cmds_paths->paths);
free((*main)->cmds_paths);
}
list_history_cleaner(*main);
rl_clear_history();
auto int exit_code = (*main)->last_exit_status;
return (free(*main), exit_code);
}
void delete_tube(t_main *main)
{
if (main->tube && main->tube->fd != -1)
{
close(main->tube->fd);
main->tube->fd = -1;
}
}
void free_cmd_path(t_main *main)
{
if (main->cmd_info->cmd_path)
free(main->cmd_info->cmd_path);
main->cmd_info->cmd_path = NULL;
}
void free_main_paths(t_main *main)
{
if (main->cmds_paths)
{
free(main->cmds_paths);
main->cmds_paths = NULL;
}
}