Skip to content

Commit 29a0614

Browse files
authored
fix dangling pointer in component pthread and dfs_elm (#9976)
* [components/libc/posix][pthreads]fix the risk of dangling pointer * [components][dfs][dfs_elm]:fix risk of dangling pointer, unmount the temp driver then free the temp FATFS in dfs_elm_mkfs.
1 parent c16d14e commit 29a0614

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ int dfs_elm_mkfs(rt_device_t dev_id, const char *fs_name)
280280
/* check flag status, we need clear the temp driver stored in disk[] */
281281
if (flag == FSM_STATUS_USE_TEMP_DRIVER)
282282
{
283-
rt_free(fat);
284283
f_mount(RT_NULL, logic_nbr, (BYTE)index);
284+
rt_free(fat);
285285
disk[index] = RT_NULL;
286286
/* close device */
287287
rt_device_close(dev_id);

components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ int dfs_elm_mkfs(rt_device_t dev_id, const char *fs_name)
319319
/* check flag status, we need clear the temp driver stored in disk[] */
320320
if (flag == FSM_STATUS_USE_TEMP_DRIVER)
321321
{
322-
rt_free(fat);
323322
f_mount(RT_NULL, logic_nbr, (BYTE)index);
323+
rt_free(fat);
324324
disk[index] = RT_NULL;
325325
/* close device */
326326
rt_device_close(dev_id);

components/libc/posix/pthreads/pthread.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,6 @@ void _pthread_data_destroy(_pthread_data_t *ptd)
169169
/* clean magic */
170170
ptd->magic = 0x0;
171171

172-
/* clear the "ptd->tid->pthread_data" */
173-
ptd->tid->pthread_data = RT_NULL;
174-
175172
/* free ptd */
176173
rt_free(ptd);
177174
}
@@ -185,6 +182,9 @@ static void _pthread_cleanup(rt_thread_t tid)
185182
/* restore tid stack */
186183
rt_free(tid->stack_addr);
187184

185+
/* clear the "ptd->tid->pthread_data" */
186+
tid->pthread_data = RT_NULL;
187+
188188
/* restore tid control block */
189189
rt_free(tid);
190190
}

0 commit comments

Comments
 (0)