Skip to content

Commit 3c1de0e

Browse files
committed
drivers flash_simulator_native: Set flash file to close on exec
If the process does an exec() (or fork, or..) all descriptors are kept open by default, unless O_CLOEXEC is set when opening them. This is usefull for stdin/out/err so that new process is connected to them, but it is very rare for it to be usefull for any other descriptor. In general this leads to descriptors being kept open unnecessarily, which either will block other process from getting them (for example if the child survives the parent but it does something else). Or for a "leak" which unnecessarily uses descriptors and memory in the child process. Let's ensure we do not leak it for this component as we do not need it. Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent 83712fb commit 3c1de0e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/flash/flash_simulator_native.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int flash_mock_init_native(bool flash_in_ram, uint8_t **mock_flash, unsigned int
5050
return -1;
5151
}
5252
} else {
53-
*flash_fd = open(flash_file_path, O_RDWR | O_CREAT, (mode_t)0600);
53+
*flash_fd = open(flash_file_path, O_RDWR | O_CREAT | O_CLOEXEC, (mode_t)0600);
5454
if (*flash_fd == -1) {
5555
nsi_print_warning("Failed to open flash device file "
5656
"%s: %s\n",

0 commit comments

Comments
 (0)