Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions core/shared/mem-alloc/ems/ems_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,14 +570,14 @@ gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size,
}
}


hmu = alloc_hmu_ex(heap, tot_size);
if (!hmu)
goto finish;

bh_assert(hmu_get_size(hmu) >= tot_size);
/* the total size allocated may be larger than
the required size, reset it here */
tot_size = hmu_get_size(hmu);
g_total_malloc += tot_size;

hmu_set_ut(hmu, HMU_VO);
Expand All @@ -590,7 +590,6 @@ gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size,
ret = hmu_to_obj(hmu);

finish:
os_mutex_unlock(&heap->lock);

if (ret) {
obj_size = tot_size - HMU_SIZE - OBJ_PREFIX_SIZE - OBJ_SUFFIX_SIZE;
Expand All @@ -599,10 +598,14 @@ gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size,
obj_size_old = tot_size_old - HMU_SIZE
- OBJ_PREFIX_SIZE - OBJ_SUFFIX_SIZE;
bh_memcpy_s(ret, obj_size, obj_old, obj_size_old);
gc_free_vo(vheap, obj_old);
}
}

os_mutex_unlock(&heap->lock);

if (ret && obj_old)
gc_free_vo(vheap, obj_old);

return ret;
}

Expand Down