Skip to content

Commit

Permalink
malloc: fix realloc copy size
Browse files Browse the repository at this point in the history
[ upstream commit a029a06 ]

In rte_realloc, if the old element has pad and need to allocate a new
memory, the padding size was not deducted, so more data was copied to
new data area.

Fixes: af75078 ("first public release")

Signed-off-by: Xueming Li <xuemingl@mellanox.com>
Reviewed-by: Anatoly Burakov <anatoly.burakov@intel.com>
  • Loading branch information
Xueming Li authored and kevintraynor committed Dec 11, 2019
1 parent 35e995e commit 23419ce
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/librte_eal/common/rte_malloc.c
Expand Up @@ -130,7 +130,8 @@ rte_realloc(void *ptr, size_t size, unsigned align)
void *new_ptr = rte_malloc(NULL, size, align);
if (new_ptr == NULL)
return NULL;
const unsigned old_size = elem->size - MALLOC_ELEM_OVERHEAD;
/* elem: |pad|data_elem|data|trailer| */
const size_t old_size = elem->size - elem->pad - MALLOC_ELEM_OVERHEAD;
rte_memcpy(new_ptr, ptr, old_size < size ? old_size : size);
rte_free(ptr);

Expand Down

0 comments on commit 23419ce

Please sign in to comment.