Skip to content

Commit 06f8875

Browse files
fxysunshinexiaoxiang781216
authored andcommitted
arch/sim: do not free memory of zero-length reallocation
Follow the change: apache#9151, if MM_CUSTOMIZE_MANAGER is enabled, heap memory manager in host is used, for example in sim:asan build. malloc and related allocation APIs will fall back to host_realloc, do not free memory of zero-length reallocation. So memory allocations return valid pointer when request zero size in all sim build. call stack: malloc() (mm/umm_heap/umm_malloc.c) mm_malloc() (arch/sim/src/sim/sim_heap.c) mm_realloc() (arch/sim/src/sim/sim_heap.c) host_realloc() (arch/sim/src/sim/posix/sim_hostmemory.c) host_memalign() (arch/sim/src/sim/posix/sim_hostmemory.c) Signed-off-by: fangxinyong <[email protected]>
1 parent 73257ee commit 06f8875

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

arch/sim/src/sim/posix/sim_hostmemory.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,7 @@ void *host_realloc(void *oldmem, size_t size)
217217
size_t oldsize;
218218
void *mem;
219219

220-
if (size == 0)
221-
{
222-
host_free(oldmem);
223-
return NULL;
224-
}
225-
else if (oldmem == NULL)
220+
if (oldmem == NULL)
226221
{
227222
return host_memalign(sizeof(void *), size);
228223
}

0 commit comments

Comments
 (0)