malloc: Print error when oldsize is not equal to the current size.
Commit Message
This is used to detect errors early.
---
malloc/malloc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
ping again.
the read of the oldsize is not protected by any lock, so check this value to avoid causing bigger mistakes.
On 2021/3/26 19:05, liqingqing wrote:
> This is used to detect errors early.
>
> ---
> malloc/malloc.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 530c792997..243be0da68 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -4784,7 +4784,8 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,
>
> /* oldmem size */
> if (__builtin_expect (chunksize_nomask (oldp) <= CHUNK_HDR_SZ, 0)
> - || __builtin_expect (oldsize >= av->system_mem, 0))
> + || __builtin_expect (oldsize >= av->system_mem, 0)
> + || __builtin_expect (oldsize != chunksize (oldp), 0))
> malloc_printerr ("realloc(): invalid old size");
>
> check_inuse_chunk (av, oldp);
LGTM; committed. Sorry for the delay.
Reviewed-by: DJ Delorie <dj@redhat.com>
@@ -4784,7 +4784,8 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,
/* oldmem size */
if (__builtin_expect (chunksize_nomask (oldp) <= CHUNK_HDR_SZ, 0)
- || __builtin_expect (oldsize >= av->system_mem, 0))
+ || __builtin_expect (oldsize >= av->system_mem, 0)
+ || __builtin_expect (oldsize != chunksize (oldp), 0))
malloc_printerr ("realloc(): invalid old size");
check_inuse_chunk (av, oldp);