summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Leech <andrew.leech@planetinnovation.com.au>2024-02-16 13:02:28 +1100
committerDamien George <damien@micropython.org>2024-02-21 09:51:52 +1100
commit2962e24167a7416d4caf8d25f463e67b46c3a40a (patch)
treec07eb7c464928d02d933596654745fcc8bfac8c5
parent31e131bd712ac118074052689e3976aed3564586 (diff)
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 <andrew.leech@planetinnovation.com.au>
-rw-r--r--extmod/vfs_posix_file.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/extmod/vfs_posix_file.c b/extmod/vfs_posix_file.c
index 46a866a78..eb9146d47 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;