review realloc

This commit is contained in:
daanx 2023-04-18 19:48:40 -07:00
parent e6f3647556
commit b549c88e6c

View File

@ -700,14 +700,12 @@ void* _mi_heap_realloc_zero(mi_heap_t* heap, void* p, size_t newsize, bool zero)
if (zero && newsize > size) { if (zero && newsize > size) {
// also set last word in the previous allocation to zero to ensure any padding is zero-initialized // also set last word in the previous allocation to zero to ensure any padding is zero-initialized
const size_t start = (size >= sizeof(intptr_t) ? size - sizeof(intptr_t) : 0); const size_t start = (size >= sizeof(intptr_t) ? size - sizeof(intptr_t) : 0);
memset((uint8_t*)newp + start, 0, newsize - start); _mi_memzero((uint8_t*)newp + start, newsize - start);
} }
if mi_likely(p != NULL) { if mi_likely(p != NULL) {
if mi_likely(_mi_is_aligned(p, sizeof(uintptr_t))) { // a client may pass in an arbitrary pointer `p`.. const size_t copysize = (newsize > size ? size : newsize);
const size_t copysize = (newsize > size ? size : newsize); mi_track_mem_defined(p,copysize); // _mi_useable_size may be too large for byte precise memory tracking..
mi_track_mem_defined(p,copysize); // _mi_useable_size may be too large for byte precise memory tracking.. _mi_memcpy(newp, p, copysize);
_mi_memcpy_aligned(newp, p, copysize);
}
mi_free(p); // only free the original pointer if successful mi_free(p); // only free the original pointer if successful
} }
} }