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>
pull/13684/head
Andrew Leech 2024-02-16 13:02:28 +11:00 zatwierdzone przez Damien George
rodzic 31e131bd71
commit 2962e24167
1 zmienionych plików z 1 dodań i 0 usunięć

Wyświetl plik

@ -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;