diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2011-09-14 08:13:26 +0930 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2011-09-14 08:13:26 +0930 |
commit | 5fac36f5adcc3bd483fa5b4e068db3c1174e8a4a (patch) | |
tree | eb6b2eb5e02d217e2095c30c282d62e4c1cd7c1d /lib/tdb2/test/run-57-die-during-transaction.c | |
parent | 1cb92ea9cf3efcc5f4295b7aeb8ddd10e174127c (diff) | |
download | samba-5fac36f5adcc3bd483fa5b4e068db3c1174e8a4a.tar.gz samba-5fac36f5adcc3bd483fa5b4e068db3c1174e8a4a.tar.bz2 samba-5fac36f5adcc3bd483fa5b4e068db3c1174e8a4a.zip |
tdb2: test: fix run-57-die-during-transaction.c to be more efficient.
We track malloc and free, but we didn't catch the free() inside
external_agent, which means that our list of allocations keeps
growing. Particularly under valgrind, which re-uses memory less than
the glibc allocator.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(Imported from CCAN commit d9cbd7d4454ae35e4e2f6d18a9469bf26948e4b9)
Diffstat (limited to 'lib/tdb2/test/run-57-die-during-transaction.c')
-rw-r--r-- | lib/tdb2/test/run-57-die-during-transaction.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/tdb2/test/run-57-die-during-transaction.c b/lib/tdb2/test/run-57-die-during-transaction.c index 6e9cb1e3e7..42102ae732 100644 --- a/lib/tdb2/test/run-57-die-during-transaction.c +++ b/lib/tdb2/test/run-57-die-during-transaction.c @@ -15,8 +15,9 @@ static int ftruncate_check(int fd, off_t length); /* There's a malloc inside transaction_setup_recovery, and valgrind complains * when we longjmp and leak it. */ -#define MAX_ALLOCATIONS 200 +#define MAX_ALLOCATIONS 10 static void *allocated[MAX_ALLOCATIONS]; +static unsigned max_alloc = 0; static void *malloc_noleak(size_t len) { @@ -25,6 +26,10 @@ static void *malloc_noleak(size_t len) for (i = 0; i < MAX_ALLOCATIONS; i++) if (!allocated[i]) { allocated[i] = malloc(len); + if (i > max_alloc) { + max_alloc = i; + diag("max_alloc: %i", max_alloc); + } return allocated[i]; } diag("Too many allocations!"); @@ -37,6 +42,10 @@ static void *realloc_noleak(void *p, size_t size) for (i = 0; i < MAX_ALLOCATIONS; i++) { if (allocated[i] == p) { + if (i > max_alloc) { + max_alloc = i; + diag("max_alloc: %i", max_alloc); + } return allocated[i] = realloc(p, size); } } @@ -270,6 +279,7 @@ int main(int argc, char *argv[]) plan_tests(24); unlock_callback = maybe_die; + external_agent_free = free_noleak; agent = prepare_external_agent(); if (!agent) err(1, "preparing agent"); |