|
From: <sv...@va...> - 2016-10-05 05:18:37
|
Author: sewardj
Date: Wed Oct 5 06:18:29 2016
New Revision: 16012
Log:
Merge, from trunk:
r15984 Added meta mempool support into memcheck Fixes BZ#367995
r15985 Fix test so that leaked bytes is the same in 32 and 64 bits
r15986 Add an optional 2nd arg to leak-autofreepool to test performance
r15987 mc-manual.xml: Fix some mismatched open/close tags.
Added:
branches/VALGRIND_3_12_BRANCH/memcheck/tests/filter_overlaperror
- copied unchanged from r15984, trunk/memcheck/tests/filter_overlaperror
branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool-0.stderr.exp
- copied unchanged from r15984, trunk/memcheck/tests/leak-autofreepool-0.stderr.exp
branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool-0.vgtest
- copied unchanged from r15984, trunk/memcheck/tests/leak-autofreepool-0.vgtest
branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool-1.stderr.exp
- copied unchanged from r15984, trunk/memcheck/tests/leak-autofreepool-1.stderr.exp
branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool-1.vgtest
- copied unchanged from r15984, trunk/memcheck/tests/leak-autofreepool-1.vgtest
branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool-2.stderr.exp
- copied unchanged from r15984, trunk/memcheck/tests/leak-autofreepool-2.stderr.exp
branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool-2.vgtest
- copied unchanged from r15984, trunk/memcheck/tests/leak-autofreepool-2.vgtest
branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool-3.stderr.exp
- copied unchanged from r15984, trunk/memcheck/tests/leak-autofreepool-3.stderr.exp
branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool-3.vgtest
- copied unchanged from r15984, trunk/memcheck/tests/leak-autofreepool-3.vgtest
branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool-4.stderr.exp
- copied unchanged from r15984, trunk/memcheck/tests/leak-autofreepool-4.stderr.exp
branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool-4.vgtest
- copied unchanged from r15984, trunk/memcheck/tests/leak-autofreepool-4.vgtest
branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool-5.stderr.exp
- copied unchanged from r15984, trunk/memcheck/tests/leak-autofreepool-5.stderr.exp
branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool-5.vgtest
- copied unchanged from r15984, trunk/memcheck/tests/leak-autofreepool-5.vgtest
branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool.c
- copied, changed from r15984, trunk/memcheck/tests/leak-autofreepool.c
Modified:
branches/VALGRIND_3_12_BRANCH/ (props changed)
branches/VALGRIND_3_12_BRANCH/NEWS (contents, props changed)
branches/VALGRIND_3_12_BRANCH/include/valgrind.h
branches/VALGRIND_3_12_BRANCH/memcheck/docs/mc-manual.xml
branches/VALGRIND_3_12_BRANCH/memcheck/mc_errors.c
branches/VALGRIND_3_12_BRANCH/memcheck/mc_include.h
branches/VALGRIND_3_12_BRANCH/memcheck/mc_leakcheck.c
branches/VALGRIND_3_12_BRANCH/memcheck/mc_main.c
branches/VALGRIND_3_12_BRANCH/memcheck/mc_malloc_wrappers.c
branches/VALGRIND_3_12_BRANCH/memcheck/tests/ (props changed)
branches/VALGRIND_3_12_BRANCH/memcheck/tests/Makefile.am
Modified: branches/VALGRIND_3_12_BRANCH/NEWS
==============================================================================
--- branches/VALGRIND_3_12_BRANCH/NEWS (original)
+++ branches/VALGRIND_3_12_BRANCH/NEWS Wed Oct 5 06:18:29 2016
@@ -8,6 +8,11 @@
* Memcheck:
+ - Added meta mempool support for describing a custom allocator which:
+ - Auto-frees all chunks assuming that destroying a pool destroys all
+ objects in the pool
+ - Uses itself to allocate other memory blocks
+
* Helgrind:
* Callgrind:
@@ -164,6 +169,7 @@
366138 Fix configure errors out when using Xcode 8 (clang 8.0.0)
366344 Multiple unhandled instruction for Aarch64
(0x0EE0E020, 0x1AC15800, 0x4E284801, 0x5E040023, 0x5E056060)
+367995 Integration of memcheck with custom memory allocator
368412 False positive result for altivec capability check
368461 mmapunmap test fails on ppc64
368416 Add tc06_two_races_xml.exp output for ppc64
Modified: branches/VALGRIND_3_12_BRANCH/include/valgrind.h
==============================================================================
--- branches/VALGRIND_3_12_BRANCH/include/valgrind.h (original)
+++ branches/VALGRIND_3_12_BRANCH/include/valgrind.h Wed Oct 5 06:18:29 2016
@@ -7009,6 +7009,22 @@
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CREATE_MEMPOOL, \
pool, rzB, is_zeroed, 0, 0)
+/* Create a memory pool with special flags. When the VALGRIND_MEMPOOL_AUTO_FREE
+ is passed, a MEMPOOL_DELETE will auto-free all chunks (so not reported as
+ leaks) for allocators that assume that destroying a pool destroys all
+ objects in the pool. When VALGRIND_MEMPOOL_METAPOOL is passed, the custom
+ allocator uses the pool blocks as superblocks to dole out MALLOC_LIKE blocks.
+ The resulting behaviour would normally be classified as overlapping blocks,
+ and cause assert-errors in valgrind.
+ These 2 MEMPOOL flags can be OR-ed together into the "flags" argument.
+ When flags is zero, the behaviour is identical to VALGRIND_CREATE_MEMPOOL.
+*/
+#define VALGRIND_MEMPOOL_AUTO_FREE 1
+#define VALGRIND_MEMPOOL_METAPOOL 2
+#define VALGRIND_CREATE_META_MEMPOOL(pool, rzB, is_zeroed, flags) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CREATE_MEMPOOL, \
+ pool, rzB, is_zeroed, flags, 0)
+
/* Destroy a memory pool. */
#define VALGRIND_DESTROY_MEMPOOL(pool) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DESTROY_MEMPOOL, \
Modified: branches/VALGRIND_3_12_BRANCH/memcheck/docs/mc-manual.xml
==============================================================================
--- branches/VALGRIND_3_12_BRANCH/memcheck/docs/mc-manual.xml (original)
+++ branches/VALGRIND_3_12_BRANCH/memcheck/docs/mc-manual.xml Wed Oct 5 06:18:29 2016
@@ -2320,6 +2320,40 @@
</listitem>
<listitem>
+ <para>
+ <varname>VALGRIND_CREATE_META_MEMPOOL(pool, rzB, is_zeroed, flags)</varname>:
+ This does the same as <varname>VALGRIND_CREATE_MEMPOOL</varname>,
+ but allows you to specify two seldom-used options for custom
+ allocators (or-ed together) in the <varname>flags</varname> argument:</para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ <varname>VALGRIND_MEMPOOL_AUTO_FREE</varname>.
+ This indicates that items allocated from this
+ memory pool are automatically freed when
+ <varname>VALGRIND_MEMPOOL_FREE</varname>
+ is used on a block. This allows a custom allocator to delete
+ (part of) a memory pool without explicitly deleting all allocated
+ items. Without this option, such an action will report all items
+ in the pool as memory leaks.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <varname>VALGRIND_MEMPOOL_METAPOOL</varname>.
+ This indicates that memory that has been
+ marked as being allocated with
+ <varname>VALGRIND_MALLOCLIKE_BLOCK</varname> is used
+ by a custom allocator to pass out memory to an application (again
+ marked with <varname>VALGRIND_MALLOCLIKE_BLOCK</varname>).
+ Without this option, such overlapping memory blocks may trigger
+ a fatal error message in memcheck.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </listitem>
+
+ <listitem>
<para><varname>VALGRIND_DESTROY_MEMPOOL(pool)</varname>:
This request tells Memcheck that a pool is being torn down. Memcheck
then removes all records of chunks associated with the pool, as well
Modified: branches/VALGRIND_3_12_BRANCH/memcheck/mc_errors.c
==============================================================================
--- branches/VALGRIND_3_12_BRANCH/memcheck/mc_errors.c (original)
+++ branches/VALGRIND_3_12_BRANCH/memcheck/mc_errors.c Wed Oct 5 06:18:29 2016
@@ -925,6 +925,30 @@
VG_(maybe_record_error)( tid, Err_User, a, /*s*/NULL, &extra );
}
+Bool MC_(is_mempool_block)(MC_Chunk* mc_search)
+{
+ MC_Mempool* mp;
+
+ if (!MC_(mempool_list))
+ return False;
+
+ // A chunk can only come from a mempool if a custom allocator
+ // is used. No search required for other kinds.
+ if (mc_search->allockind == MC_AllocCustom) {
+ VG_(HT_ResetIter)( MC_(mempool_list) );
+ while ( (mp = VG_(HT_Next)(MC_(mempool_list))) ) {
+ MC_Chunk* mc;
+ VG_(HT_ResetIter)(mp->chunks);
+ while ( (mc = VG_(HT_Next)(mp->chunks)) ) {
+ if (mc == mc_search)
+ return True;
+ }
+ }
+ }
+
+ return False;
+}
+
/*------------------------------------------------------------*/
/*--- Other error operations ---*/
/*------------------------------------------------------------*/
@@ -1016,7 +1040,8 @@
// Forward declarations
static Bool client_block_maybe_describe( Addr a, AddrInfo* ai );
-static Bool mempool_block_maybe_describe( Addr a, AddrInfo* ai );
+static Bool mempool_block_maybe_describe( Addr a, Bool is_metapool,
+ AddrInfo* ai );
/* Describe an address as best you can, for error messages,
@@ -1031,10 +1056,12 @@
if (client_block_maybe_describe( a, ai )) {
return;
}
- /* -- Perhaps it's in mempool block? -- */
- if (mempool_block_maybe_describe( a, ai )) {
+
+ /* -- Perhaps it's in mempool block (non-meta)? -- */
+ if (mempool_block_maybe_describe( a, /*is_metapool*/ False, ai)) {
return;
}
+
/* Blocks allocated by memcheck malloc functions are either
on the recently freed list or on the malloc-ed list.
Custom blocks can be on both : a recently freed block might
@@ -1046,7 +1073,8 @@
/* -- Search for a currently malloc'd block which might bracket it. -- */
VG_(HT_ResetIter)(MC_(malloc_list));
while ( (mc = VG_(HT_Next)(MC_(malloc_list))) ) {
- if (addr_is_in_MC_Chunk_default_REDZONE_SZB(mc, a)) {
+ if (!MC_(is_mempool_block)(mc) &&
+ addr_is_in_MC_Chunk_default_REDZONE_SZB(mc, a)) {
ai->tag = Addr_Block;
ai->Addr.Block.block_kind = Block_Mallocd;
if (MC_(get_freed_block_bracketting)( a ))
@@ -1063,7 +1091,7 @@
}
/* -- Search for a recently freed block which might bracket it. -- */
mc = MC_(get_freed_block_bracketting)( a );
- if (mc) {
+ if (mc && !MC_(is_mempool_block)(mc)) {
ai->tag = Addr_Block;
ai->Addr.Block.block_kind = Block_Freed;
ai->Addr.Block.block_desc = "block";
@@ -1075,6 +1103,16 @@
return;
}
+ /* -- Perhaps it's in a meta mempool block? -- */
+ /* This test is done last, because metapool blocks overlap with blocks
+ handed out to the application. That makes every heap address part of
+ a metapool block, so the interesting cases are handled first.
+ This final search is a last-ditch attempt. When found, it is probably
+ an error in the custom allocator itself. */
+ if (mempool_block_maybe_describe( a, /*is_metapool*/ True, ai )) {
+ return;
+ }
+
/* No block found. Search a non-heap block description. */
VG_(describe_addr) (a, ai);
}
@@ -1215,7 +1253,7 @@
}
-static Bool mempool_block_maybe_describe( Addr a,
+static Bool mempool_block_maybe_describe( Addr a, Bool is_metapool,
/*OUT*/AddrInfo* ai )
{
MC_Mempool* mp;
@@ -1223,7 +1261,7 @@
VG_(HT_ResetIter)( MC_(mempool_list) );
while ( (mp = VG_(HT_Next)(MC_(mempool_list))) ) {
- if (mp->chunks != NULL) {
+ if (mp->chunks != NULL && mp->metapool == is_metapool) {
MC_Chunk* mc;
VG_(HT_ResetIter)(mp->chunks);
while ( (mc = VG_(HT_Next)(mp->chunks)) ) {
Modified: branches/VALGRIND_3_12_BRANCH/memcheck/mc_include.h
==============================================================================
--- branches/VALGRIND_3_12_BRANCH/memcheck/mc_include.h (original)
+++ branches/VALGRIND_3_12_BRANCH/memcheck/mc_include.h Wed Oct 5 06:18:29 2016
@@ -93,6 +93,9 @@
Addr pool; // pool identifier
SizeT rzB; // pool red-zone size
Bool is_zeroed; // allocations from this pool are zeroed
+ Bool auto_free; // De-alloc block frees all chunks in block
+ Bool metapool; // These chunks are VALGRIND_MALLOC_LIKE
+ // memory, and used as pool.
VgHashTable *chunks; // chunks associated with this pool
}
MC_Mempool;
@@ -105,7 +108,8 @@
void MC_(handle_free) ( ThreadId tid,
Addr p, UInt rzB, MC_AllocKind kind );
-void MC_(create_mempool) ( Addr pool, UInt rzB, Bool is_zeroed );
+void MC_(create_mempool) ( Addr pool, UInt rzB, Bool is_zeroed,
+ Bool auto_free, Bool metapool );
void MC_(destroy_mempool) ( Addr pool );
void MC_(mempool_alloc) ( ThreadId tid, Addr pool,
Addr addr, SizeT size );
@@ -114,6 +118,7 @@
void MC_(move_mempool) ( Addr poolA, Addr poolB );
void MC_(mempool_change) ( Addr pool, Addr addrA, Addr addrB, SizeT size );
Bool MC_(mempool_exists) ( Addr pool );
+Bool MC_(is_mempool_block)( MC_Chunk* mc_search );
/* Searches for a recently freed block which might bracket Addr a.
Return the MC_Chunk* for this block or NULL if no bracketting block
Modified: branches/VALGRIND_3_12_BRANCH/memcheck/mc_leakcheck.c
==============================================================================
--- branches/VALGRIND_3_12_BRANCH/memcheck/mc_leakcheck.c (original)
+++ branches/VALGRIND_3_12_BRANCH/memcheck/mc_leakcheck.c Wed Oct 5 06:18:29 2016
@@ -1760,6 +1760,25 @@
VG_(free)(seg_starts);
}
+static MC_Mempool *find_mp_of_chunk (MC_Chunk* mc_search)
+{
+ MC_Mempool* mp;
+
+ tl_assert( MC_(mempool_list) );
+
+ VG_(HT_ResetIter)( MC_(mempool_list) );
+ while ( (mp = VG_(HT_Next)(MC_(mempool_list))) ) {
+ MC_Chunk* mc;
+ VG_(HT_ResetIter)(mp->chunks);
+ while ( (mc = VG_(HT_Next)(mp->chunks)) ) {
+ if (mc == mc_search)
+ return mp;
+ }
+ }
+
+ return NULL;
+}
+
/*------------------------------------------------------------*/
/*--- Top-level entry point. ---*/
/*------------------------------------------------------------*/
@@ -1816,7 +1835,7 @@
tl_assert( lc_chunks[i]->data <= lc_chunks[i+1]->data);
}
- // Sanity check -- make sure they don't overlap. The one exception is that
+ // Sanity check -- make sure they don't overlap. One exception is that
// we allow a MALLOCLIKE block to sit entirely within a malloc() block.
// This is for bug 100628. If this occurs, we ignore the malloc() block
// for leak-checking purposes. This is a hack and probably should be done
@@ -1825,6 +1844,9 @@
// for mempool chunks, but if custom-allocated blocks are put in a separate
// table from normal heap blocks it makes free-mismatch checking more
// difficult.
+ // Another exception: Metapool memory blocks overlap by definition. The meta-
+ // block is allocated (by a custom allocator), and chunks of that block are
+ // allocated again for use by the application: Not an error.
//
// If this check fails, it probably means that the application
// has done something stupid with VALGRIND_MALLOCLIKE_BLOCK client
@@ -1867,15 +1889,48 @@
lc_n_chunks--;
} else {
- VG_(umsg)("Block 0x%lx..0x%lx overlaps with block 0x%lx..0x%lx\n",
- start1, end1, start2, end2);
- VG_(umsg)("Blocks allocation contexts:\n"),
- VG_(pp_ExeContext)( MC_(allocated_at)(ch1));
- VG_(umsg)("\n"),
- VG_(pp_ExeContext)( MC_(allocated_at)(ch2));
- VG_(umsg)("This is usually caused by using VALGRIND_MALLOCLIKE_BLOCK");
- VG_(umsg)("in an inappropriate way.\n");
- tl_assert (0);
+ // Overlap is allowed ONLY when one of the two candicates is a block
+ // from a memory pool that has the metapool attribute set.
+ // All other mixtures trigger the error + assert.
+ MC_Mempool* mp;
+ Bool ch1_is_meta = False, ch2_is_meta = False;
+ Bool Inappropriate = False;
+
+ if (MC_(is_mempool_block)(ch1)) {
+ mp = find_mp_of_chunk(ch1);
+ if (mp && mp->metapool) {
+ ch1_is_meta = True;
+ }
+ }
+
+ if (MC_(is_mempool_block)(ch2)) {
+ mp = find_mp_of_chunk(ch2);
+ if (mp && mp->metapool) {
+ ch2_is_meta = True;
+ }
+ }
+
+ // If one of the blocks is a meta block, the other must be entirely
+ // within that meta block, or something is really wrong with the custom
+ // allocator.
+ if (ch1_is_meta != ch2_is_meta) {
+ if ( (ch1_is_meta && (start2 < start1 || end2 > end1)) ||
+ (ch2_is_meta && (start1 < start2 || end1 > end2)) ) {
+ Inappropriate = True;
+ }
+ }
+
+ if (ch1_is_meta == ch2_is_meta || Inappropriate) {
+ VG_(umsg)("Block 0x%lx..0x%lx overlaps with block 0x%lx..0x%lx\n",
+ start1, end1, start2, end2);
+ VG_(umsg)("Blocks allocation contexts:\n"),
+ VG_(pp_ExeContext)( MC_(allocated_at)(ch1));
+ VG_(umsg)("\n"),
+ VG_(pp_ExeContext)( MC_(allocated_at)(ch2));
+ VG_(umsg)("This is usually caused by using ");
+ VG_(umsg)("VALGRIND_MALLOCLIKE_BLOCK in an inappropriate way.\n");
+ tl_assert (0);
+ }
}
}
Modified: branches/VALGRIND_3_12_BRANCH/memcheck/mc_main.c
==============================================================================
--- branches/VALGRIND_3_12_BRANCH/memcheck/mc_main.c (original)
+++ branches/VALGRIND_3_12_BRANCH/memcheck/mc_main.c Wed Oct 5 06:18:29 2016
@@ -7032,8 +7032,13 @@
Addr pool = (Addr)arg[1];
UInt rzB = arg[2];
Bool is_zeroed = (Bool)arg[3];
+ UInt flags = arg[4];
- MC_(create_mempool) ( pool, rzB, is_zeroed );
+ // The create_mempool function does not know these mempool flags,
+ // pass as booleans.
+ MC_(create_mempool) ( pool, rzB, is_zeroed,
+ (flags & VALGRIND_MEMPOOL_AUTO_FREE),
+ (flags & VALGRIND_MEMPOOL_METAPOOL) );
return True;
}
Modified: branches/VALGRIND_3_12_BRANCH/memcheck/mc_malloc_wrappers.c
==============================================================================
--- branches/VALGRIND_3_12_BRANCH/memcheck/mc_malloc_wrappers.c (original)
+++ branches/VALGRIND_3_12_BRANCH/memcheck/mc_malloc_wrappers.c Wed Oct 5 06:18:29 2016
@@ -338,7 +338,8 @@
/* Allocate memory and note change in memory available */
void* MC_(new_block) ( ThreadId tid,
Addr p, SizeT szB, SizeT alignB,
- Bool is_zeroed, MC_AllocKind kind, VgHashTable *table)
+ Bool is_zeroed, MC_AllocKind kind,
+ VgHashTable *table)
{
MC_Chunk* mc;
@@ -674,14 +675,52 @@
static void check_mempool_sane(MC_Mempool* mp); /*forward*/
+static void free_mallocs_in_mempool_block (MC_Mempool* mp,
+ Addr StartAddr,
+ Addr EndAddr)
+{
+ MC_Chunk *mc;
+ ThreadId tid;
+ Bool found;
-void MC_(create_mempool)(Addr pool, UInt rzB, Bool is_zeroed)
+ tl_assert(mp->auto_free);
+
+ if (VG_(clo_verbosity) > 2) {
+ VG_(message)(Vg_UserMsg,
+ "free_mallocs_in_mempool_block: Start 0x%lx size %lu\n",
+ StartAddr, (SizeT) (EndAddr - StartAddr));
+ }
+
+ tid = VG_(get_running_tid)();
+
+ do {
+ found = False;
+
+ VG_(HT_ResetIter)(MC_(malloc_list));
+ while (!found && (mc = VG_(HT_Next)(MC_(malloc_list))) ) {
+ if (mc->data >= StartAddr && mc->data + mc->szB < EndAddr) {
+ if (VG_(clo_verbosity) > 2) {
+ VG_(message)(Vg_UserMsg, "Auto-free of 0x%lx size=%lu\n",
+ mc->data, (mc->szB + 0UL));
+ }
+
+ mc = VG_(HT_remove) ( MC_(malloc_list), (UWord) mc->data);
+ die_and_free_mem(tid, mc, mp->rzB);
+ found = True;
+ }
+ }
+ } while (found);
+}
+
+void MC_(create_mempool)(Addr pool, UInt rzB, Bool is_zeroed,
+ Bool auto_free, Bool metapool)
{
MC_Mempool* mp;
if (VG_(clo_verbosity) > 2) {
- VG_(message)(Vg_UserMsg, "create_mempool(0x%lx, %u, %d)\n",
- pool, rzB, is_zeroed);
+ VG_(message)(Vg_UserMsg,
+ "create_mempool(0x%lx, rzB=%u, zeroed=%d, autofree=%d, metapool=%d)\n",
+ pool, rzB, is_zeroed, auto_free, metapool);
VG_(get_and_pp_StackTrace)
(VG_(get_running_tid)(), MEMPOOL_DEBUG_STACKTRACE_DEPTH);
}
@@ -695,6 +734,8 @@
mp->pool = pool;
mp->rzB = rzB;
mp->is_zeroed = is_zeroed;
+ mp->auto_free = auto_free;
+ mp->metapool = metapool;
mp->chunks = VG_(HT_construct)( "MC_(create_mempool)" );
check_mempool_sane(mp);
@@ -882,10 +923,14 @@
return;
}
+ if (mp->auto_free) {
+ free_mallocs_in_mempool_block(mp, mc->data, mc->data + (mc->szB + 0UL));
+ }
+
if (VG_(clo_verbosity) > 2) {
VG_(message)(Vg_UserMsg,
- "mempool_free(0x%lx, 0x%lx) freed chunk of %lu bytes\n",
- pool, addr, mc->szB + 0UL);
+ "mempool_free(0x%lx, 0x%lx) freed chunk of %lu bytes\n",
+ pool, addr, mc->szB + 0UL);
}
die_and_free_mem ( tid, mc, mp->rzB );
Modified: branches/VALGRIND_3_12_BRANCH/memcheck/tests/Makefile.am
==============================================================================
--- branches/VALGRIND_3_12_BRANCH/memcheck/tests/Makefile.am (original)
+++ branches/VALGRIND_3_12_BRANCH/memcheck/tests/Makefile.am Wed Oct 5 06:18:29 2016
@@ -61,7 +61,8 @@
filter_stderr filter_xml \
filter_strchr \
filter_varinfo3 \
- filter_memcheck
+ filter_memcheck \
+ filter_overlaperror
noinst_HEADERS = leak.h
@@ -155,6 +156,12 @@
leak-pool-3.vgtest leak-pool-3.stderr.exp \
leak-pool-4.vgtest leak-pool-4.stderr.exp \
leak-pool-5.vgtest leak-pool-5.stderr.exp \
+ leak-autofreepool-0.vgtest leak-autofreepool-0.stderr.exp \
+ leak-autofreepool-1.vgtest leak-autofreepool-1.stderr.exp \
+ leak-autofreepool-2.vgtest leak-autofreepool-2.stderr.exp \
+ leak-autofreepool-3.vgtest leak-autofreepool-3.stderr.exp \
+ leak-autofreepool-4.vgtest leak-autofreepool-4.stderr.exp \
+ leak-autofreepool-5.vgtest leak-autofreepool-5.stderr.exp \
leak-tree.vgtest leak-tree.stderr.exp \
leak-segv-jmp.vgtest leak-segv-jmp.stderr.exp \
lks.vgtest lks.stdout.exp lks.supp lks.stderr.exp \
@@ -347,6 +354,7 @@
leak-cycle \
leak-delta \
leak-pool \
+ leak-autofreepool \
leak-tree \
leak-segv-jmp \
long-supps \
Copied: branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool.c (from r15984, trunk/memcheck/tests/leak-autofreepool.c)
==============================================================================
--- trunk/memcheck/tests/leak-autofreepool.c (original)
+++ branches/VALGRIND_3_12_BRANCH/memcheck/tests/leak-autofreepool.c Wed Oct 5 06:18:29 2016
@@ -1,4 +1,4 @@
-
+#include <time.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
@@ -35,7 +35,7 @@
struct cell
{
struct cell *next;
- int x;
+ char x[16 - sizeof(void*)];
};
static struct pool _PlainPool, *PlainPool = &_PlainPool;
@@ -182,7 +182,7 @@
int arg;
size_t i;
- assert(argc == 2);
+ assert(argc == 2 || argc == 3);
assert(argv[1]);
assert(strlen(argv[1]) == 1);
assert(argv[1][0] >= '0' && argv[1][0] <= '9');
@@ -222,5 +222,62 @@
// Cleanup.
VALGRIND_DESTROY_MEMPOOL(PlainPool);
+ // Perf test
+ if (argc == 3) {
+ struct pool perf_plain_pool;
+ void *perf_plain_block;
+ struct pool perf_meta_pool;
+ void *perf_meta_block;
+ size_t pool_block_size;
+ int n;
+ int nr_elts = atoi( argv[2] );
+ time_t dnow;
+#define tprintf(...) (dnow = time(NULL), \
+ printf(__VA_ARGS__), \
+ printf(" %s", ctime(&dnow)))
+
+ pool_block_size = nr_elts * sizeof(struct cell) + sizeof(uint8_t) + 1;
+
+ // Create perf meta pool
+ VALGRIND_CREATE_META_MEMPOOL
+ (&perf_meta_pool, 0, 0,
+ VALGRIND_MEMPOOL_AUTO_FREE | VALGRIND_MEMPOOL_METAPOOL);
+ perf_meta_block = malloc(pool_block_size);
+
+ VALGRIND_MEMPOOL_ALLOC(&perf_meta_pool, perf_meta_block,
+ pool_block_size);
+
+ perf_meta_pool.buf = (uint8_t *) perf_meta_block;
+ perf_meta_pool.allocated = pool_block_size;
+ perf_meta_pool.used = 0;
+
+
+ perf_meta_pool.buf += sizeof(uint8_t);
+ perf_meta_pool.used += sizeof(uint8_t);
+
+ // Create perf plain pool
+ VALGRIND_CREATE_MEMPOOL(&perf_plain_pool, 0, 0);
+ perf_plain_block = malloc(pool_block_size);
+
+ perf_plain_pool.buf = (uint8_t *) perf_plain_block;
+ perf_plain_pool.allocated = pool_block_size;;
+ perf_plain_pool.used = 0;
+
+ perf_plain_pool.buf += sizeof(uint8_t);
+ perf_plain_pool.used += sizeof(uint8_t);
+
+ tprintf("allocating %d elts", nr_elts);
+ for (n = 0; n < nr_elts; n++) {
+ (void) allocate_meta_style (&perf_meta_pool, sizeof(struct cell));
+ (void) allocate_plain_style (&perf_plain_pool, sizeof(struct cell));
+ }
+
+ tprintf("freeing mempool");
+ VALGRIND_MEMPOOL_FREE(&perf_meta_pool, perf_meta_block);
+ tprintf("destroying mempool");
+ VALGRIND_DESTROY_MEMPOOL(&perf_meta_pool);
+ tprintf("done");
+
+ }
return 0;
}
|