realloc: use copy_size to check for canaries

This avoids unnecessarily copying the canary when doing a realloc from a
small size to a large size. It also avoids trying to copy a non-existent
canary out of a zero-size allocation, which are memory protected.
This commit is contained in:
Daniel Micay 2019-06-17 00:23:03 -04:00
parent 37474e117c
commit bc75c4db7b

View File

@ -1474,7 +1474,7 @@ EXPORT void *h_realloc(void *old, size_t size) {
return NULL;
}
size_t copy_size = min(size, old_size);
if (size > 0 && size <= max_slab_size_class) {
if (copy_size > 0 && copy_size <= max_slab_size_class) {
copy_size -= canary_size;
}
memcpy(new, old, copy_size);