Skip to content

Commit 2962e24

Browse files
pi-anldpgeorge
authored andcommitted
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 micropython#13672. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent 31e131b commit 2962e24

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

extmod/vfs_posix_file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_
9292
}
9393

9494
mp_obj_vfs_posix_file_t *o = mp_obj_malloc_with_finaliser(mp_obj_vfs_posix_file_t, type);
95+
o->fd = -1; // In case open() fails below, initialise this as a "closed" file object.
9596

9697
mp_obj_t fid = file_in;
9798

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy