diff --git a/components/micropython/vendor/extmod/vfs_posix_file.c b/components/micropython/vendor/extmod/vfs_posix_file.c index a270b78ecbbf7fd2e483dd5bdd5dbef9bb5ef86b..0095b38ca380dd5f346a427493848826b6448d46 100644 --- a/components/micropython/vendor/extmod/vfs_posix_file.c +++ b/components/micropython/vendor/extmod/vfs_posix_file.c @@ -187,7 +187,18 @@ STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_ case MP_STREAM_CLOSE: if (o->fd >= 0) { MP_THREAD_GIL_EXIT(); - close(o->fd); + switch (o->fd) { + case 0: + case 1: + case 2: + // Don't let anything close stdin/stdout/stderr. + // BUG: we shouldn't even get to this point of anything + // attempting to close these. But that's for someone else to + // debug. + break; + default: + close(o->fd); + } MP_THREAD_GIL_ENTER(); } o->fd = -1; @@ -249,4 +260,4 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &vfs_posix_rawfile_locals_dict ); -#endif // MICROPY_VFS_POSIX \ No newline at end of file +#endif // MICROPY_VFS_POSIX