diff --git a/sys/fs/msdosfs/msdosfs_fat.c b/sys/fs/msdosfs/msdosfs_fat.c index 96c9f187fdcb..7a3ade3a3d2d 100644 --- a/sys/fs/msdosfs/msdosfs_fat.c +++ b/sys/fs/msdosfs/msdosfs_fat.c @@ -691,8 +691,11 @@ chainalloc(struct msdosfsmount *pmp, u_long start, u_long count, pmp->pm_nxtfree = CLUST_FIRST; pmp->pm_flags |= MSDOSFS_FSIMOD; error = fatchain(pmp, start, count, fillwith); - if (error != 0) + if (error != 0) { + for (cl = start, n = count; n-- > 0;) + usemap_free(pmp, cl++); return (error); + } #ifdef MSDOSFS_DEBUG printf("clusteralloc(): allocated cluster chain at %lu (%lu clusters)\n", start, count);