]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
Bash-5.1 patch 9: fix bash malloc implementation of malloc_usable_size
authorChet Ramey <chet.ramey@case.edu>
Wed, 17 Nov 2021 21:44:19 +0000 (16:44 -0500)
committerChet Ramey <chet.ramey@case.edu>
Wed, 17 Nov 2021 21:44:19 +0000 (16:44 -0500)
lib/malloc/malloc.c
patchlevel.h

index 439f8ef11af247b5e53f0512543a0e6ddd122002..92e6efa52f7be3ed009f13b3cd63aa7d80d6bcd9 100644 (file)
@@ -1286,13 +1286,12 @@ malloc_usable_size (mem)
       p = (union mhead *) ap - 1;
     }
 
-  /* XXX - should we return 0 if ISFREE? */
-  maxbytes = binsize(p->mh_index);
-
-  /* So the usable size is the maximum number of bytes in the bin less the
-     malloc overhead */
-  maxbytes -= MOVERHEAD + MSLOP;
-  return (maxbytes);
+  /* return 0 if ISFREE */
+  if (p->mh_alloc == ISFREE)
+    return 0;
+  
+  /* Since we use bounds checking, the usable size is the last requested size. */
+  return (p->mh_nbytes);
 }
 
 #if !defined (NO_VALLOC)
index 10fde2eee1386e47902806f4e4eb478f9ecd75eb..17586ff7f5cf0994d637531533e12f2453e02f5e 100644 (file)
@@ -25,6 +25,6 @@
    regexp `^#define[   ]*PATCHLEVEL', since that's what support/mkversion.sh
    looks for to find the patch level (for the sccs version string). */
 
-#define PATCHLEVEL 8
+#define PATCHLEVEL 9
 
 #endif /* _PATCHLEVEL_H_ */