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

This commit is contained in:
prife 2013-01-22 23:47:32 +08:00
parent 05544d12c9
commit a4d661dcf1
1 changed files with 6 additions and 0 deletions

View File

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