]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
malloc_usable_size() was totally broken, crashing immediately.
authorNicholas Nethercote <njn@valgrind.org>
Wed, 17 Aug 2005 04:03:31 +0000 (04:03 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Wed, 17 Aug 2005 04:03:31 +0000 (04:03 +0000)
I guess it's not very widely used :)

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4439

coregrind/m_mallocfree.c
coregrind/pub_core_mallocfree.h
coregrind/pub_core_replacemalloc.h
memcheck/tests/Makefile.am
memcheck/tests/malloc_usable.c [new file with mode: 0644]
memcheck/tests/malloc_usable.stderr.exp [new file with mode: 0644]
memcheck/tests/malloc_usable.vgtest [new file with mode: 0644]

index 1aa4ef3ea61280d0ee9662570901617501b2eea3..e21ed6290cb9b87b8dbbdce9bfd9278de0bf9edb 100644 (file)
@@ -1197,7 +1197,7 @@ void* VG_(arena_memalign) ( ArenaId aid, SizeT req_alignB, SizeT req_pszB )
 }
 
 
-SizeT VG_(arena_payload_szB) ( ArenaId aid, void* ptr )
+SizeT VG_(arena_payload_szB) ( ThreadId tid, ArenaId aid, void* ptr )
 {
    Arena* a = arenaId_to_ArenaP(aid);
    Block* b = get_payload_block(a, ptr);
index b5b7ec22bbfe716d3d001cc3a81611f7efab8b7a..94dcbc69c468ecd5339ef89a9f82615e5bb2b08f 100644 (file)
@@ -81,7 +81,7 @@ extern Char* VG_(arena_strdup)  ( ArenaId aid, const Char* s);
    must be called before any of VG_(malloc) and friends are called. */
 extern void  VG_(set_client_malloc_redzone_szB) ( SizeT rz_szB );
 
-extern SizeT VG_(arena_payload_szB) ( ArenaId aid, void* payload );
+extern SizeT VG_(arena_payload_szB) ( ThreadId tid, ArenaId aid, void* p );
 
 extern void  VG_(sanity_check_malloc_all) ( void );
 
index 3484a6e02e3435541891e84f25a2e5c692ffaf03..e50de51d7841bd11e778fe4bfd069f7eefc7c390 100644 (file)
@@ -50,7 +50,7 @@ struct vg_mallocfunc_info {
    void  (*tl___builtin_vec_delete)(ThreadId tid, void* p);
    void* (*tl_realloc)             (ThreadId tid, void* p, SizeT size);
 
-   SizeT (*arena_payload_szB)      (ArenaId aid, void* payload);
+   SizeT (*arena_payload_szB)      (ThreadId tid, ArenaId aid, void* payload);
    Bool        clo_trace_malloc;
 };
 
index 251eb6eadd665a767a30191f5b4560814053ff04..5e59567eb50a3d395758234c04c5a69b845e96fd 100644 (file)
@@ -39,6 +39,7 @@ EXTRA_DIST = $(noinst_SCRIPTS) \
        leak-tree.stderr.exp2 leak-tree.stderr.exp64 \
        leak-regroot.vgtest leak-regroot.stderr.exp \
        leakotron.vgtest leakotron.stdout.exp leakotron.stderr.exp \
+       malloc_usable.stderr.exp malloc_usable.vgtest \
        malloc1.stderr.exp malloc1.vgtest \
        malloc2.stderr.exp malloc2.vgtest \
        malloc3.stderr.exp malloc3.stdout.exp malloc3.vgtest \
@@ -99,7 +100,7 @@ check_PROGRAMS = \
        doublefree error_counts errs1 exitprog execve execve2 erringfds \
        fprw fwrite hello inits inline \
        leak-0 leak-cycle leak-tree leak-regroot leakotron \
-       malloc1 malloc2 malloc3 manuel1 manuel2 manuel3 \
+       malloc_usable malloc1 malloc2 malloc3 manuel1 manuel2 manuel3 \
        match-overrun \
        memalign_test memalign2 memcmptest mempool mmaptest \
        nanoleak new_nothrow \
diff --git a/memcheck/tests/malloc_usable.c b/memcheck/tests/malloc_usable.c
new file mode 100644 (file)
index 0000000..670bc98
--- /dev/null
@@ -0,0 +1,12 @@
+#include <assert.h>
+#include <malloc.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(void)
+{
+   // Since our allocations are in multiples of 8, 99 will round up to 104.
+   int* x = malloc(99);
+   assert(104 == malloc_usable_size(x));
+   return 0;
+}
diff --git a/memcheck/tests/malloc_usable.stderr.exp b/memcheck/tests/malloc_usable.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/memcheck/tests/malloc_usable.vgtest b/memcheck/tests/malloc_usable.vgtest
new file mode 100644 (file)
index 0000000..407d872
--- /dev/null
@@ -0,0 +1,2 @@
+prog: malloc_usable
+vgopts: -q