瀏覽代碼

fix memory leak in dfs_elm.c and umount fatfs when mount fatfs fails (this bug leads to mkfs failure in linux)

prife 12 年之前
父節點
當前提交
a4d661dcf1
共有 1 個文件被更改,包括 6 次插入0 次删除
  1. 6 0
      components/dfs/filesystems/elmfat/dfs_elm.c

+ 6 - 0
components/dfs/filesystems/elmfat/dfs_elm.c

@@ -123,7 +123,12 @@ int dfs_elm_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *d
         rt_snprintf(drive, sizeof(drive), "%d:/", index);
         dir = (DIR *)rt_malloc(sizeof(DIR));
         if (dir == RT_NULL)
+        {
+            f_mount((BYTE)index, RT_NULL);
+            disk[index] = RT_NULL;
+            rt_free(fat);
             return -DFS_STATUS_ENOMEM;
+        }
 
         /* open the root directory to test whether the fatfs is valid */
         result = f_opendir(dir, drive);
@@ -137,6 +142,7 @@ int dfs_elm_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *d
     }
 
 __err:
+    f_mount((BYTE)index, RT_NULL);
     disk[index] = RT_NULL;
     rt_free(fat);
     return elm_result_to_dfs(result);