Skip to content

Commit 81e77aa

Browse files
committed
main.c: unmount user-mounted vfs regardless of order
1 parent 3d22d52 commit 81e77aa

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

main.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,22 @@ static void start_mp(safe_mode_t safe_mode) {
211211

212212
static void stop_mp(void) {
213213
#if MICROPY_VFS
214-
mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table);
215214

216215
// Unmount all heap allocated vfs mounts.
217-
while (gc_ptr_on_heap(vfs)) {
216+
mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table);
217+
do {
218+
if (gc_ptr_on_heap(vfs)) {
219+
// mp_vfs_umount will splice out an unmounted vfs from the vfs_mount_table linked list.
220+
mp_vfs_umount(vfs->obj);
221+
// Start over at the beginning of the list since the first entry may have been removed.
222+
vfs = MP_STATE_VM(vfs_mount_table);
223+
continue;
224+
}
218225
vfs = vfs->next;
219-
}
220-
MP_STATE_VM(vfs_mount_table) = vfs;
226+
} while (vfs != NULL);
227+
221228
// The last vfs is CIRCUITPY and the root directory.
229+
vfs = MP_STATE_VM(vfs_mount_table);
222230
while (vfs->next != NULL) {
223231
vfs = vfs->next;
224232
}

0 commit comments

Comments
 (0)