mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-10-22 00:03:02 +08:00
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:
@@ -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);
|
||||||
|
Reference in New Issue
Block a user