Skip to content

Commit 8e8ae9c

Browse files
committed
[src][memheap] Fix the crash problem after opening Oz optimization on ac6.
1 parent 2c119a5 commit 8e8ae9c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/memheap.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* 2013-05-24 Bernard fix the rt_memheap_realloc issue.
1818
* 2013-07-11 Grissiom fix the memory block splitting issue.
1919
* 2013-07-15 Grissiom optimize rt_memheap_realloc
20+
* 2021-06-03 Flybreak Fix the crash problem after opening Oz optimization on ac6.
2021
*/
2122

2223
#include <rthw.h>
@@ -369,7 +370,8 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
369370
if (newsize > oldsize)
370371
{
371372
void *new_ptr;
372-
struct rt_memheap_item *next_ptr;
373+
/* Fix the crash problem after opening Oz optimization on ac6 */
374+
volatile struct rt_memheap_item *next_ptr;
373375

374376
/* lock memheap */
375377
result = rt_sem_take(&(heap->lock), RT_WAITING_FOREVER);
@@ -441,14 +443,14 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
441443

442444
next_ptr->prev = header_ptr;
443445
next_ptr->next = header_ptr->next;
444-
header_ptr->next->prev = next_ptr;
445-
header_ptr->next = next_ptr;
446+
header_ptr->next->prev = (struct rt_memheap_item *)next_ptr;
447+
header_ptr->next = (struct rt_memheap_item *)next_ptr;
446448

447449
/* insert next_ptr to free list */
448450
next_ptr->next_free = heap->free_list->next_free;
449451
next_ptr->prev_free = heap->free_list;
450-
heap->free_list->next_free->prev_free = next_ptr;
451-
heap->free_list->next_free = next_ptr;
452+
heap->free_list->next_free->prev_free = (struct rt_memheap_item *)next_ptr;
453+
heap->free_list->next_free = (struct rt_memheap_item *)next_ptr;
452454
RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("new ptr: next_free 0x%08x, prev_free 0x%08x",
453455
next_ptr->next_free,
454456
next_ptr->prev_free));

0 commit comments

Comments
 (0)