leaks are no more (for real this time)
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
|
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/19 17:59:31 by tomoron ### ########.fr */
|
/* Updated: 2024/04/19 18:49:33 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -61,9 +61,10 @@ void exec_command_bonus(t_msh *msh, char *cmd_str)
|
|||||||
free_cmd(cmds);
|
free_cmd(cmds);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
msh->cmds_head = cmds;
|
||||||
while (cmds)
|
while (cmds)
|
||||||
{
|
{
|
||||||
print_parsed_cmd(cmds); // debug
|
//print_parsed_cmd(cmds); // debug
|
||||||
msh->tokens = parse_cmds_to_token(cmds, msh->env);
|
msh->tokens = parse_cmds_to_token(cmds, msh->env);
|
||||||
msh->cmds = cmds;
|
msh->cmds = cmds;
|
||||||
//print_msh_struct(msh); // debug
|
//print_msh_struct(msh); // debug
|
||||||
@ -73,6 +74,7 @@ void exec_command_bonus(t_msh *msh, char *cmd_str)
|
|||||||
msh->out_fd = 0;
|
msh->out_fd = 0;
|
||||||
cmds = get_next_command(cmds);
|
cmds = get_next_command(cmds);
|
||||||
}
|
}
|
||||||
|
free_cmd(msh->cmds_head);
|
||||||
}
|
}
|
||||||
|
|
||||||
int exec(t_msh *msh, char **cmd_args, int i, int cmd_count)
|
int exec(t_msh *msh, char **cmd_args, int i, int cmd_count)
|
||||||
@ -180,6 +182,7 @@ void end_execution(t_msh *msh, int cmd_count)
|
|||||||
print_signaled(status);
|
print_signaled(status);
|
||||||
// TODO: (core dumped) WCOREDUMP
|
// TODO: (core dumped) WCOREDUMP
|
||||||
free(msh->pids);
|
free(msh->pids);
|
||||||
|
free_fds(msh);
|
||||||
msh->pids = 0;
|
msh->pids = 0;
|
||||||
free(msh->fds);
|
free(msh->fds);
|
||||||
// signal(SIGINT, signal_handler_interactive); //enables ctrl-C
|
// signal(SIGINT, signal_handler_interactive); //enables ctrl-C
|
||||||
@ -197,7 +200,7 @@ void exec_commands(t_msh *msh)
|
|||||||
return ;
|
return ;
|
||||||
cmd_count = get_cmd_count(msh->cmds);
|
cmd_count = get_cmd_count(msh->cmds);
|
||||||
//printf("cmd_count : %d\n", cmd_count);
|
//printf("cmd_count : %d\n", cmd_count);
|
||||||
msh->fds = ft_calloc(cmd_count, sizeof(int **));
|
msh->fds = ft_calloc(cmd_count + 1, sizeof(int **));
|
||||||
msh->pids = ft_calloc(cmd_count, sizeof(int *));
|
msh->pids = ft_calloc(cmd_count, sizeof(int *));
|
||||||
if (!msh->pids || !msh->fds)
|
if (!msh->pids || !msh->fds)
|
||||||
ft_exit(msh, 1);
|
ft_exit(msh, 1);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/19 14:09:25 by tomoron ### ########.fr */
|
/* Updated: 2024/04/19 18:49:27 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -65,6 +65,7 @@ typedef struct s_msh
|
|||||||
t_env *env;
|
t_env *env;
|
||||||
t_token *tokens;
|
t_token *tokens;
|
||||||
t_cmd *cmds;
|
t_cmd *cmds;
|
||||||
|
t_cmd *cmds_head;
|
||||||
int **fds;
|
int **fds;
|
||||||
int *pids;
|
int *pids;
|
||||||
t_cmd_type in_type;
|
t_cmd_type in_type;
|
||||||
@ -143,6 +144,7 @@ int ft_export(t_msh *msh);
|
|||||||
int is_input_type(t_cmd *cmd);
|
int is_input_type(t_cmd *cmd);
|
||||||
void free_env(t_env *env);
|
void free_env(t_env *env);
|
||||||
int ft_unset(t_msh *msh);
|
int ft_unset(t_msh *msh);
|
||||||
|
void free_fds(t_msh *msh);
|
||||||
void free_msh(t_msh *msh);
|
void free_msh(t_msh *msh);
|
||||||
void free_msh(t_msh *msh);
|
void free_msh(t_msh *msh);
|
||||||
int echo(t_token *args);
|
int echo(t_token *args);
|
||||||
|
22
srcs/utils.c
22
srcs/utils.c
@ -6,18 +6,38 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/04/18 20:49:01 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/19 18:52:13 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
void free_fds(t_msh *msh)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (msh->fds)
|
||||||
|
{
|
||||||
|
i = 0;
|
||||||
|
while (msh->fds[i])
|
||||||
|
{
|
||||||
|
free(msh->fds[i]);
|
||||||
|
msh->fds[i] = 0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
free(msh->fds);
|
||||||
|
msh->fds = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void free_msh(t_msh *msh)
|
void free_msh(t_msh *msh)
|
||||||
{
|
{
|
||||||
if (msh)
|
if (msh)
|
||||||
{
|
{
|
||||||
free_env(msh->env);
|
free_env(msh->env);
|
||||||
free(msh->pids);
|
free(msh->pids);
|
||||||
|
free_cmd(msh->cmds_head);
|
||||||
|
free_fds(msh);
|
||||||
free_token(msh->tokens);
|
free_token(msh->tokens);
|
||||||
set_echoctl(msh->echoctl);
|
set_echoctl(msh->echoctl);
|
||||||
free(msh);
|
free(msh);
|
||||||
|
Reference in New Issue
Block a user