Parcourir la source

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.
lingfengPeng il y a 1 mois
Parent
commit
29a06142c5

+ 1 - 1
components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c

@@ -280,8 +280,8 @@ int dfs_elm_mkfs(rt_device_t dev_id, const char *fs_name)
     /* check flag status, we need clear the temp driver stored in disk[] */
     if (flag == FSM_STATUS_USE_TEMP_DRIVER)
     {
-        rt_free(fat);
         f_mount(RT_NULL, logic_nbr, (BYTE)index);
+        rt_free(fat);
         disk[index] = RT_NULL;
         /* close device */
         rt_device_close(dev_id);

+ 1 - 1
components/dfs/dfs_v2/filesystems/elmfat/dfs_elm.c

@@ -319,8 +319,8 @@ int dfs_elm_mkfs(rt_device_t dev_id, const char *fs_name)
     /* check flag status, we need clear the temp driver stored in disk[] */
     if (flag == FSM_STATUS_USE_TEMP_DRIVER)
     {
-        rt_free(fat);
         f_mount(RT_NULL, logic_nbr, (BYTE)index);
+        rt_free(fat);
         disk[index] = RT_NULL;
         /* close device */
         rt_device_close(dev_id);

+ 3 - 3
components/libc/posix/pthreads/pthread.c

@@ -169,9 +169,6 @@ void _pthread_data_destroy(_pthread_data_t *ptd)
         /* clean magic */
         ptd->magic = 0x0;
 
-        /* clear the "ptd->tid->pthread_data" */
-        ptd->tid->pthread_data = RT_NULL;
-
         /* free ptd */
         rt_free(ptd);
     }
@@ -185,6 +182,9 @@ static void _pthread_cleanup(rt_thread_t tid)
     /* restore tid stack */
     rt_free(tid->stack_addr);
 
+    /* clear the "ptd->tid->pthread_data" */
+    tid->pthread_data = RT_NULL;
+
     /* restore tid control block */
     rt_free(tid);
 }