realloc(): struct sys_mem_pool_block is word aligned

Since commit 39cd2ebef7 ("malloc: make sure returned memory is
properly aligned") the size of struct sys_mem_pool_block size is
rounded up to the next word boundary.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2019-07-11 15:51:24 -04:00 committed by Carles Cufí
commit 8e11970378

View file

@ -88,6 +88,7 @@ void *calloc(size_t nmemb, size_t size)
void *realloc(void *ptr, size_t requested_size)
{
struct sys_mem_pool_block *blk;
size_t struct_blk_size = WB_UP(sizeof(struct sys_mem_pool_block));
size_t block_size, total_requested_size;
void *new_ptr;
@ -101,7 +102,7 @@ void *realloc(void *ptr, size_t requested_size)
}
/* Stored right before the pointer passed to the user */
blk = (struct sys_mem_pool_block *)((char *)ptr - sizeof(*blk));
blk = (struct sys_mem_pool_block *)((char *)ptr - struct_blk_size);
/* Determine size of previously allocated block by its level.
* Most likely a bit larger than the original allocation
@ -112,8 +113,7 @@ void *realloc(void *ptr, size_t requested_size)
}
/* We really need this much memory */
total_requested_size = requested_size +
sizeof(struct sys_mem_pool_block);
total_requested_size = requested_size + struct_blk_size;
if (block_size >= total_requested_size) {
/* Existing block large enough, nothing to do */
@ -125,7 +125,7 @@ void *realloc(void *ptr, size_t requested_size)
return NULL;
}
memcpy(new_ptr, ptr, block_size - sizeof(struct sys_mem_pool_block));
memcpy(new_ptr, ptr, block_size - struct_blk_size);
free(ptr);
return new_ptr;