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.
This commit is contained in:
Khaïs COLIN 2025-04-29 12:58:26 +02:00
parent 3c350af411
commit 93f3ea7c66
16 changed files with 111 additions and 89 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/04 19:42:36 by khais #+# #+# */
/* Updated: 2025/04/16 16:45:40 by khais ### ########.fr */
/* Updated: 2025/04/29 14:40:03 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,6 +15,6 @@
# include "../../minishell.h"
void group_cmd_execute(t_group_cmd *cmd, t_minishell *app, bool should_exit);
t_subprocess group_cmd_execute(t_group_cmd *cmd, t_minishell *app);
#endif // GROUP_CMD_EXECUTE_H