From 2962e24167a7416d4caf8d25f463e67b46c3a40a Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Fri, 16 Feb 2024 13:02:28 +1100 Subject: [PATCH] extmod/vfs_posix_file: Ensure file object has safe default fd. With this commit, if file open fails, the object will have fd = -1 (closed) and the finaliser will not attempt to close anything. Fixes issue #13672. Signed-off-by: Andrew Leech --- extmod/vfs_posix_file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/extmod/vfs_posix_file.c b/extmod/vfs_posix_file.c index 46a866a78a..eb9146d47b 100644 --- a/extmod/vfs_posix_file.c +++ b/extmod/vfs_posix_file.c @@ -92,6 +92,7 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_ } mp_obj_vfs_posix_file_t *o = mp_obj_malloc_with_finaliser(mp_obj_vfs_posix_file_t, type); + o->fd = -1; // In case open() fails below, initialise this as a "closed" file object. mp_obj_t fid = file_in;