benchmark: Malloc Assertion Failure with Basic Benchmarking Sample
Hi, I’m still an amateur to this library. I came across this error and wasn’t able find a way to fix it.
I Tried to Run a very basic code to benchmark a function that prints ‘Hello World’. The execution fails with a malloc assertion error.
Environment
Kernel-Version : 3.16.0-4-amd64 Hardware : x86_64 Linux Release : Debian GNU/Linux 9 Page Size : 4096 gcc Version : 6.3.0
Code
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<benchmark/benchmark.h>
using namespace std;
void helloWorld()
{
printf("Hello World");
}
static void bench_helloWorld(benchmark::State &state)
{
while(state.KeepRunning())
{
helloWorld();
}
}
int main()
{
BENCHMARK(bench_helloWorld);
return 0;
}
Error Message
Test.out: malloc.c:2406: sysmalloc: Assertion '(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
Valgrind Output
==25622== Invalid write of size 8
==25622== at 0x40D878: benchmark::internal::Benchmark::Benchmark(char const*) (in /home/s2group/MKL_Perf/Test.out)
==25622== by 0x404E2E: benchmark::internal::FunctionBenchmark::FunctionBenchmark(char const*, void (*)(benchmark::State&)) (benchmark.h:989)
==25622== by 0x404D52: main (BuggyCode.cpp:22)
==25622== Address 0x6554030 is 0 bytes after a block of size 176 alloc'd
==25622== at 0x4C2C21F: operator new(unsigned long) (vg_replace_malloc.c:334)
==25622== by 0x404D3D: main (BuggyCode.cpp:22)
==25622==
==25622== Invalid write of size 8
==25622== at 0x40D883: benchmark::internal::Benchmark::Benchmark(char const*) (in /home/s2group/MKL_Perf/Test.out)
==25622== by 0x404E2E: benchmark::internal::FunctionBenchmark::FunctionBenchmark(char const*, void (*)(benchmark::State&)) (benchmark.h:989)
==25622== by 0x404D52: main (BuggyCode.cpp:22)
==25622== Address 0x6554038 is 8 bytes after a block of size 176 alloc'd
==25622== at 0x4C2C21F: operator new(unsigned long) (vg_replace_malloc.c:334)
==25622== by 0x404D3D: main (BuggyCode.cpp:22)
==25622==
==25622== Invalid free() / delete / delete[] / realloc()
==25622== at 0x4C2D2DB: operator delete(void*) (vg_replace_malloc.c:576)
==25622== by 0x40D1EE: benchmark::internal::Benchmark::~Benchmark() (in /home/s2group/MKL_Perf/Test.out)
==25622== by 0x4115AF: benchmark::internal::FunctionBenchmark::~FunctionBenchmark() (in /home/s2group/MKL_Perf/Test.out)
==25622== by 0x411305: benchmark::internal::BenchmarkFamilies::~BenchmarkFamilies() (in /home/s2group/MKL_Perf/Test.out)
==25622== by 0x5FD493F: __run_exit_handlers (exit.c:83)
==25622== by 0x5FD4999: exit (exit.c:105)
==25622== by 0x5FBF2E7: (below main) (libc-start.c:325)
==25622== Address 0x404bab is in the Text segment of /home/s2group/MKL_Perf/Test.out
==25622== at 0x404BAB: bench_helloWorld(benchmark::State&) (BuggyCode.cpp:12)
==25622==
==25622==
==25622== HEAP SUMMARY:
==25622== in use at exit: 0 bytes in 0 blocks
==25622== total heap usage: 12 allocs, 13 frees, 73,573 bytes allocated
==25622==
==25622== All heap blocks were freed -- no leaks are possible
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (1 by maintainers)
Finally!
Thank You So Much, LebedevRI and dominichamon. It was a version mismatch issue as LebedevRI suggested. Sorry for bothering you.
That should now be
for (auto _ : state)That is very clearly incorrect. See https://github.com/google/benchmark#basic-usage