free leaks
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/27 11:25:25 by lderidde #+# #+# */
|
||||
/* Updated: 2025/02/05 09:55:28 by lderidde ### ########.fr */
|
||||
/* Updated: 2025/02/07 09:22:29 by lderidde ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -22,6 +22,7 @@ typedef struct s_msh
|
||||
{
|
||||
int ex_code;
|
||||
t_ast_n *head;
|
||||
char *input;
|
||||
char **env;
|
||||
} t_msh;
|
||||
|
||||
@@ -43,6 +44,7 @@ typedef struct s_msh
|
||||
|
||||
t_msh *init_msh(char **envp);
|
||||
void free_msh(t_msh *msh);
|
||||
void free_child(t_msh *msh);
|
||||
|
||||
# define POW1 "\033[1;38;2;21;22;26;48;2;92;106;178m"
|
||||
# define POW2 "\033[1;38;2;92;106;178;48;2;54;54;54m"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/27 11:22:33 by lderidde #+# #+# */
|
||||
/* Updated: 2025/02/06 14:08:10 by lderidde ### ########.fr */
|
||||
/* Updated: 2025/02/07 09:28:49 by lderidde ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -285,6 +285,7 @@ void exec_pcmd(t_ast_n *pcmd)
|
||||
if (is_builtin(pcmd->cmd))
|
||||
{
|
||||
ret = exec_builtin(pcmd);
|
||||
free_child(pcmd->msh);
|
||||
exit(ret);
|
||||
}
|
||||
else
|
||||
@@ -296,6 +297,9 @@ int execute_shcommand(t_ast_n *node);
|
||||
|
||||
void exec_pchild(int *pipes, int index, t_ast_n *pcmd, int cmds)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = 0;
|
||||
if (index < cmds - 1)
|
||||
dup2(pipes[1], STDOUT_FILENO);
|
||||
close(pipes[0]);
|
||||
@@ -304,7 +308,11 @@ void exec_pchild(int *pipes, int index, t_ast_n *pcmd, int cmds)
|
||||
if (pcmd->state == _CMD)
|
||||
exec_pcmd(pcmd);
|
||||
else if (pcmd->state == _SUBSH)
|
||||
exit (execute_shcommand(pcmd->left));
|
||||
{
|
||||
ret = execute_shcommand(pcmd->left);
|
||||
free_child(pcmd->msh);
|
||||
exit(ret);
|
||||
}
|
||||
}
|
||||
|
||||
int end_pline(pid_t last_pid, t_ast_n **pline)
|
||||
@@ -418,7 +426,8 @@ int exec_subsh(t_ast_n *node)
|
||||
{
|
||||
handle_redir(node->parent);
|
||||
ret = execute_shcommand(node);
|
||||
reset_redir(node->parent);
|
||||
// reset_redir(node->parent);
|
||||
free_child(node->msh);
|
||||
exit(ret);
|
||||
}
|
||||
else if (pid > 0)
|
||||
|
||||
14
srcs/main.c
14
srcs/main.c
@@ -6,7 +6,7 @@
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/27 14:16:52 by lderidde #+# #+# */
|
||||
/* Updated: 2025/02/05 13:27:18 by lderidde ### ########.fr */
|
||||
/* Updated: 2025/02/07 09:24:34 by lderidde ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -52,7 +52,6 @@ static void interpret_cmd(char **input, t_msh *msh)
|
||||
|
||||
int main(int ac, char **av, char **envp)
|
||||
{
|
||||
char *input;
|
||||
t_msh *msh;
|
||||
|
||||
(void)ac;
|
||||
@@ -60,18 +59,17 @@ int main(int ac, char **av, char **envp)
|
||||
msh = init_msh(envp);
|
||||
if (!msh)
|
||||
return (1);
|
||||
input = NULL;
|
||||
if (ac == 1)
|
||||
while (1)
|
||||
{
|
||||
while (!input || !input[0])
|
||||
input = powerline();
|
||||
interpret_cmd(&input, msh);
|
||||
while (!msh->input || !msh->input[0])
|
||||
msh->input = powerline();
|
||||
interpret_cmd(&msh->input, msh);
|
||||
}
|
||||
else
|
||||
{
|
||||
input = ft_strdup(av[1]);
|
||||
interpret_cmd(&input, msh);
|
||||
msh->input = ft_strdup(av[1]);
|
||||
interpret_cmd(&msh->input, msh);
|
||||
}
|
||||
free_msh(msh);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* msh_struct.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/06 15:32:03 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/02/06 15:32:03 by nalebrun ### ########.fr */
|
||||
/* Created: 2025/02/06 15:32:03 by lderidde #+# #+# */
|
||||
/* Updated: 2025/02/07 09:24:52 by lderidde ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -32,6 +32,7 @@ t_msh *init_msh(char **envp)
|
||||
|
||||
msh = malloc(sizeof(t_msh) * 1);
|
||||
msh->ex_code = 0;
|
||||
msh->input = NULL;
|
||||
if (!msh)
|
||||
return (NULL);
|
||||
if (!envp[0])
|
||||
@@ -43,6 +44,7 @@ t_msh *init_msh(char **envp)
|
||||
|
||||
void free_msh(t_msh *msh)
|
||||
{
|
||||
free_tab(msh->env);
|
||||
free(msh);
|
||||
free_tab(msh->env);
|
||||
free(msh->input);
|
||||
free(msh);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* free_ast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/05 14:39:28 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/02/05 14:39:28 by nalebrun ### ########.fr */
|
||||
/* Created: 2025/02/05 14:39:28 by lderidde #+# #+# */
|
||||
/* Updated: 2025/02/07 09:20:16 by lderidde ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -53,3 +53,9 @@ void free_ast(t_ast_n *node)
|
||||
free_cmd(node);
|
||||
free(node);
|
||||
}
|
||||
|
||||
void free_child(t_msh *msh)
|
||||
{
|
||||
free_ast(msh->head);
|
||||
free_msh(msh);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* subsh.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/05 07:51:27 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/02/05 07:51:27 by nalebrun ### ########.fr */
|
||||
/* Created: 2025/02/05 07:51:27 by lderidde #+# #+# */
|
||||
/* Updated: 2025/02/07 09:12:41 by lderidde ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -17,6 +17,7 @@ t_node *remove_parentheses(t_node *lst)
|
||||
t_node *it;
|
||||
t_node *out;
|
||||
int deepness;
|
||||
char *str;
|
||||
|
||||
out = NULL;
|
||||
it = lst;
|
||||
@@ -24,15 +25,18 @@ t_node *remove_parentheses(t_node *lst)
|
||||
deepness = 1;
|
||||
while (1)
|
||||
{
|
||||
str = ft_strdup(it->val);
|
||||
if (it->pressision == SUBSH_S)
|
||||
deepness += 1;
|
||||
if (it->pressision == SUBSH_E)
|
||||
deepness -= 1;
|
||||
if (deepness == 0)
|
||||
break;
|
||||
add_node_back(&out, ft_strdup(it->val), it->token, it->pressision);
|
||||
add_node_back(&out, str, it->token, it->pressision);
|
||||
free(str);
|
||||
it = it->next;
|
||||
}
|
||||
free(str);
|
||||
return (out);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* drawio_ast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/27 17:15:39 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/01/27 17:15:39 by nalebrun ### ########.fr */
|
||||
/* Created: 2025/01/27 17:15:39 by lderidde #+# #+# */
|
||||
/* Updated: 2025/02/07 09:14:08 by lderidde ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -24,12 +24,15 @@ void set_ast_rect(t_dio_elem *rect)
|
||||
|
||||
void gen_dio_ast(t_ast_n *head, int fd)
|
||||
{
|
||||
t_elems e;
|
||||
t_elems *e;
|
||||
|
||||
set_ast_rect(&e.rect);
|
||||
e.arrow.type = ARROW;
|
||||
e.arrow.id_src = 0;
|
||||
e.arrow.id_dst = 0;
|
||||
print_ast(head, &e, fd);
|
||||
e = ft_calloc(sizeof(t_elems), 1);
|
||||
set_ast_rect(&e->rect);
|
||||
e->arrow.type = ARROW;
|
||||
e->arrow.id_src = 0;
|
||||
e->arrow.id_dst = 0;
|
||||
print_ast(head, e, fd);
|
||||
free(e->rect.text);
|
||||
free(e);
|
||||
return ;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* drawio_print_ast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/29 09:54:31 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/01/29 09:54:31 by nalebrun ### ########.fr */
|
||||
/* Created: 2025/01/29 09:54:31 by lderidde #+# #+# */
|
||||
/* Updated: 2025/02/07 09:09:01 by lderidde ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -20,14 +20,15 @@ char *get_node_txt(t_ast_n *node)
|
||||
|
||||
txt = get_cmd_txt(node);
|
||||
if (node->sh == true)
|
||||
subsh = " (subsh) ";
|
||||
subsh = ft_strdup(" (subsh) ");
|
||||
else
|
||||
subsh = "";
|
||||
subsh = ft_strdup("");
|
||||
out = ft_sprintf("%s%s%s%s%s", txt.st, txt.cmd, txt.args,
|
||||
subsh, txt.files);
|
||||
free(txt.cmd);
|
||||
free(txt.args);
|
||||
free(txt.files);
|
||||
free(subsh);
|
||||
return (out);
|
||||
}
|
||||
|
||||
@@ -67,12 +68,12 @@ int print_ast(t_ast_n *node, t_elems *e, int fd)
|
||||
|
||||
if (!node)
|
||||
return (-1);
|
||||
ft_free(&e->rect.text);
|
||||
e->rect.text = get_node_txt(node);
|
||||
node_id = drawio_create_elem(fd, &e->rect);
|
||||
if (node->state != _PLINE)
|
||||
draw_bin_part(node, e, fd, node_id);
|
||||
else
|
||||
draw_pline_part(node, e, fd, node_id);
|
||||
ft_free(&e->rect.text);
|
||||
return (node_id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user