testing/mm: repair the memory leak question when realloc failed.
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
This commit is contained in:
parent
19acc783c4
commit
963c1f31db
@ -177,6 +177,7 @@ static void do_reallocs(FAR void **mem, FAR const int *oldsize,
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
void *ptr;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
@ -184,10 +185,19 @@ static void do_reallocs(FAR void **mem, FAR const int *oldsize,
|
||||
printf("(%d)Re-allocating at %p from %d to %d bytes\n",
|
||||
i, mem[j], oldsize[j], newsize[j]);
|
||||
|
||||
mem[j] = realloc(mem[j], newsize[j]);
|
||||
printf("(%d)Memory re-allocated at %p\n", i, mem[j]);
|
||||
/* Return null if realloc failed, so using a local variable to store
|
||||
* the return value to avoid the missing of old memory pointer.
|
||||
*/
|
||||
|
||||
if (mem[j] == NULL)
|
||||
ptr = realloc(mem[j], newsize[j]);
|
||||
if (ptr != NULL)
|
||||
{
|
||||
mem[j] = ptr;
|
||||
}
|
||||
|
||||
printf("(%d)Memory re-allocated at %p\n", i, ptr);
|
||||
|
||||
if (ptr == NULL)
|
||||
{
|
||||
int allocsize = MM_ALIGN_UP(newsize[j] + SIZEOF_MM_ALLOCNODE);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user