fix memory re-allocation issue

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@15 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong 2009-08-03 14:00:27 +00:00
parent bd76439fd2
commit 74f893fc2e
1 changed files with 29 additions and 28 deletions

View File

@ -342,6 +342,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
rt_size_t size; rt_size_t size;
rt_size_t ptr, ptr2; rt_size_t ptr, ptr2;
struct heap_mem *mem, *mem2; struct heap_mem *mem, *mem2;
void* nmem;
/* alignment size */ /* alignment size */
newsize = RT_ALIGN(newsize, RT_ALIGN_SIZE); newsize = RT_ALIGN(newsize, RT_ALIGN_SIZE);
@ -394,12 +395,12 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
rt_sem_release(&heap_sem); rt_sem_release(&heap_sem);
/* expand memory */ /* expand memory */
mem2 = rt_malloc(newsize); nmem = rt_malloc(newsize);
rt_memcpy(mem2, mem, size); rt_memcpy(nmem, rmem, size);
rt_free(mem); rt_free(rmem);
return mem2; return nmem;
} }
/** /**