about summary refs log tree commit diff
path: root/malloc/hooks.c
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2021-03-08 12:59:05 +0000
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2021-03-26 11:03:06 +0000
commitfaf003ed8de7c1b1b4794ae15c90241825caeea4 (patch)
tree2c89de8148b9810ebd8c0b7471ef6aa23dc41db8 /malloc/hooks.c
parent1dc17ea8f8492d618a91f0b7b3f1e7fd089889d1 (diff)
downloadglibc-faf003ed8de7c1b1b4794ae15c90241825caeea4.tar.gz
glibc-faf003ed8de7c1b1b4794ae15c90241825caeea4.tar.xz
glibc-faf003ed8de7c1b1b4794ae15c90241825caeea4.zip
malloc: Use memsize instead of CHUNK_AVAILABLE_SIZE
This is a pure refactoring change that does not affect behaviour.

The CHUNK_AVAILABLE_SIZE name was unclear, the memsize name tries to
follow the existing convention of mem denoting the allocation that is
handed out to the user, while chunk is its internally used container.

The user owned memory for a given chunk starts at chunk2mem(p) and
the size is memsize(p).  It is not valid to use on dumped heap chunks.

Moved the definition next to other chunk and mem related macros.

Reviewed-by: DJ Delorie <dj@redhat.com>
Diffstat (limited to 'malloc/hooks.c')
-rw-r--r--malloc/hooks.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/malloc/hooks.c b/malloc/hooks.c
index 9474e199c3..b82ff5781b 100644
--- a/malloc/hooks.c
+++ b/malloc/hooks.c
@@ -102,7 +102,7 @@ malloc_check_get_size (mchunkptr p)
 
   assert (using_malloc_checking == 1);
 
-  for (size = CHUNK_AVAILABLE_SIZE (p) - 1;
+  for (size = CHUNK_HDR_SZ + memsize (p) - 1;
        (c = *SAFE_CHAR_OFFSET (p, size)) != magic;
        size -= c)
     {
@@ -130,7 +130,7 @@ mem2mem_check (void *ptr, size_t req_sz)
 
   p = mem2chunk (ptr);
   magic = magicbyte (p);
-  max_sz = CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ;
+  max_sz = memsize (p);
 
   for (i = max_sz - 1; i > req_sz; i -= block_sz)
     {
@@ -175,7 +175,7 @@ mem2chunk_check (void *mem, unsigned char **magic_p)
                                next_chunk (prev_chunk (p)) != p)))
         return NULL;
 
-      for (sz = CHUNK_AVAILABLE_SIZE (p) - 1;
+      for (sz = CHUNK_HDR_SZ + memsize (p) - 1;
 	   (c = *SAFE_CHAR_OFFSET (p, sz)) != magic;
 	   sz -= c)
         {
@@ -200,7 +200,7 @@ mem2chunk_check (void *mem, unsigned char **magic_p)
           ((prev_size (p) + sz) & page_mask) != 0)
         return NULL;
 
-      for (sz = CHUNK_AVAILABLE_SIZE (p) - 1;
+      for (sz = CHUNK_HDR_SZ + memsize (p) - 1;
 	   (c = *SAFE_CHAR_OFFSET (p, sz)) != magic;
 	   sz -= c)
         {
@@ -279,8 +279,7 @@ free_check (void *mem, const void *caller)
   else
     {
       /* Mark the chunk as belonging to the library again.  */
-      (void)tag_region (chunk2rawmem (p), CHUNK_AVAILABLE_SIZE (p)
-                                         - CHUNK_HDR_SZ);
+      (void)tag_region (chunk2rawmem (p), memsize (p));
       _int_free (&main_arena, p, 1);
       __libc_lock_unlock (main_arena.mutex);
     }