From b61add87cbb2ee193f82b1db214a03a5b2e09e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sat, 13 Jan 2024 00:08:24 +0000 Subject: [PATCH] Close open file descriptors on exit. --- posix-runner/posix-runner.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/posix-runner/posix-runner.c b/posix-runner/posix-runner.c index c03d946..20b31c5 100644 --- a/posix-runner/posix-runner.c +++ b/posix-runner/posix-runner.c @@ -280,6 +280,12 @@ void sys_exit(unsigned value, void, void, void, void, void) } free(current_process->envp); + for (i = 3; i < __FILEDES_MAX; i += 1) { + if (current_process->fd_map[i] != NULL) { + sys_close(i, NULL, NULL, NULL, NULL, NULL); + } + } + if (current_process->parent == NULL) { exit(value); }