Merge pull request #1321 from TanekLiang/memheap-fixed

[Kernel][memheap] fix rt_realloc bugs
This commit is contained in:
Bernard Xiong 2018-03-28 11:14:36 +08:00 committed by GitHub
commit 8ea9dd6579
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -659,6 +659,12 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
if (rmem == RT_NULL)
return rt_malloc(newsize);
if (newsize == 0)
{
rt_free(rmem);
return RT_NULL;
}
/* get old memory item */
header_ptr = (struct rt_memheap_item *)
((rt_uint8_t *)rmem - RT_MEMHEAP_SIZE);
@ -678,6 +684,8 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
rt_memcpy(new_ptr, rmem, oldsize);
else
rt_memcpy(new_ptr, rmem, newsize);
rt_free(rmem);
}
}