malloc: Print error when oldsize is not equal to the current size.

This is used to detect errors early.  The read of the oldsize is
not protected by any lock, so check this value to avoid causing
bigger mistakes.

Reviewed-by: DJ Delorie <dj@redhat.com>
This commit is contained in:
Qingqing Li 2022-09-22 15:32:56 -04:00 committed by DJ Delorie
parent de477abcaa
commit 774d43f27d

View File

@ -4803,7 +4803,8 @@ _int_realloc (mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,
/* oldmem size */ /* oldmem size */
if (__builtin_expect (chunksize_nomask (oldp) <= CHUNK_HDR_SZ, 0) 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"); malloc_printerr ("realloc(): invalid old size");
check_inuse_chunk (av, oldp); check_inuse_chunk (av, oldp);