minishell/src/executing/group_cmd/group_cmd_execute.h
Khaïs COLIN 93f3ea7c66 fix(exec): prevent leak when calling exit() in a subprocess
This was because at the point at which exit is called, we can only free a
t_simple_cmd, but not the whole t_cmd tree. This commit introduces a convention
of returning a t_subprocess enum from each function in exec. If the current
thread is a subprocess, SUBPROCESS is returned, else PARENTPROCESS. We also no
longer call exit in subproceses. This way, all processes bubble up to main,
where if SUBPROCESS is returned, all memory is freed and the program exits.

This also removes the previous should_exit convention.

Still TODO: handling of the exit builtin, which should also bubble up in the
same way.
2025-04-29 15:20:05 +02:00

20 lines
1.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* group_cmd_execute.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/04 19:42:36 by khais #+# #+# */
/* Updated: 2025/04/29 14:40:03 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef GROUP_CMD_EXECUTE_H
# define GROUP_CMD_EXECUTE_H
# include "../../minishell.h"
t_subprocess group_cmd_execute(t_group_cmd *cmd, t_minishell *app);
#endif // GROUP_CMD_EXECUTE_H