Questions tagged [valgrind]

Valgrind is a dynamic analysis tool for Linux, FreeBSD, macOS, Android, and Solaris systems. It can be used for execution and data profiling as well as for finding memory leaks, race conditions, and threading errors.

Valgrind is an open source instrumentation framework for building dynamic analysis tools. It was originally developed on Linux and has since been ported to other UNIX-like systems. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools.

Valgrind works by effectively running your code in a virtual machine where extra instrumentation is available to monitor the behavior of your code in detail.

When instrumenting your code you should compile with debug symbols, like -g2 or -g3; and you should lower optimizations, like -O0 or -O1. Higher optimizations sometimes produce false positives. Also see The Valgrind Quick Start Guide.

Available GUIs frontends:

  • valkyrie
  • KDevelop lets you use Valgrind as a plugin
  • Eclipse has a GUI plugin to integrate Valgrind into its C++ Development Tools
  • Qt Creator can use memcheck and callgrind.

There are several tools for visualizing the Valgrind output

4117 questions
31
votes
2 answers

Invalid read of size 8 - Valgrind + C

Valgrind reports error Invalid read of size 8 in the following code. I have an array declared like, struct symbol *st[PARSER_HASH_SIZE]; When my program is initialized, all the elements in this array are initailzied as 0. memset(&st[0], 0,…
Navaneeth K N
  • 15,295
  • 38
  • 126
  • 184
31
votes
2 answers

Valgrind Unrecognised instruction

I have the following code: #include #include int main() { std::mt19937_64 rng(std::random_device{}()); std::cout << std::uniform_int_distribution<>(0, 100)(rng) << '\n'; } I try to profile it using valgrind, but it…
nwp
  • 9,623
  • 5
  • 38
  • 68
31
votes
4 answers

Error installing valgrind

i try to install valgrind on my mac but when I execute ./autogen.sh get this error: running: aclocal ./autogen.sh: line 6: aclocal: command not found error: while running 'aclocal' does anybody know how to solve this?
DRINK
  • 452
  • 1
  • 6
  • 15
30
votes
4 answers

Should I use Helgrind or DRD for thread error detection?

Looks like Valgrind has two tools that both do thread error detection: Helgrind and DRD. These tools are substantially similar. My primary question is: when should I use one instead of the other to check my multi-threaded code? More broadly, why…
Jeff Terrell Ph.D.
  • 2,563
  • 26
  • 39
29
votes
1 answer

Valgrind yells about an uninitialised bytes

Valgrind throws me out this error: ==11204== Syscall param write(buf) points to uninitialised byte(s) ==11204== at 0x4109033: write (in /lib/libc-2.13.so) ==11204== by 0x8049654: main (mmboxman.c:289) ==11204== Address 0xbe92f861 is on thread…
Damiano Barbati
  • 3,356
  • 8
  • 39
  • 51
29
votes
2 answers

What is the difference between a direct and indirect leak?

I got the following output from the LeakSanitizer tool. What is the difference between a direct and indirect leak, as the tool understands it? 13: ==29107==ERROR: LeakSanitizer: detected memory leaks 13: 13: Direct leak of 288 byte(s) in 6…
user7610
  • 25,267
  • 15
  • 124
  • 150
29
votes
6 answers

Why does this code not result in a memory leak?

I checked the following code in C++ with valgrind with --leak-check=full and it says no memory leak. Why is that? char *p = new char[256]; delete p; new[] should be matched by delete[] as far as I know.
Dan Lincan
  • 1,065
  • 2
  • 14
  • 32
28
votes
4 answers

How do I make ctest run a program with valgrind without dart?

I want to write a CMakeLists.txt so that I can run my tests normally or with valgrind. I have seen much on integrating ctest with valgrind but all with the assumption that you want to set up a server to submit test results to a dart dashboard. I…
leif
  • 1,987
  • 4
  • 19
  • 22
28
votes
1 answer

How to get the full call stack from Valgrind?

I run Valgrind with the following parameters: --leak-check=full --show-reachable=yes --leak-resolution=high --num-callers=100 --trace-children=yes In memory leaks log, I see some error messages with full stack trace up to main, but some messages…
Michael Lukin
  • 829
  • 3
  • 9
  • 19
27
votes
2 answers

Interpreting callgrind data

I need a dynamic call graph for my app. I run it with callgrind tool (valgrind suite) and got callgrind.out.xxxxx file. Now, I want to make a graphical representation of this data. KCacheGrind doesn't help me much because it draws a limited part of…
maverik
  • 5,508
  • 3
  • 35
  • 55
27
votes
5 answers

Make valgrind stop immediately after first error

my program processes large errors and during development in produces large amount of output on the console. It suffers from memory corruption and I try to use valgrind to locate the error. Unfortunately, i can't find the error messages among the…
shuhalo
  • 5,732
  • 12
  • 43
  • 60
26
votes
3 answers

How use callgrind to profiling only a certain period of program execution?

I want to use valgrind to do some profiling, since it does not need re-build the program. (the program I want to profile is already build with “-g") But valgrind(callgrind) is quite slow ... so here's what I to do: start the server ( I want to…
superb
  • 963
  • 1
  • 10
  • 21
25
votes
1 answer

How to interpret results from kcachegrind

Could anyone tell me how to interest the results from kcachegrind. I had two versions of my code (v1, v2) both compiled in debug mode. I ran them through valgrind with options: valgrind --tool=callgrind -v .... The output files thus generated are…
rkm
  • 892
  • 2
  • 16
  • 32
25
votes
5 answers

why pthread causes a memory leak

Whenever I create a pthread, valgrind outputs a memory leak, For example the below code: #include #include #include void *timer1_function (void *eit){ (void) eit; printf("hello world\n"); …
Johan Elmander
  • 646
  • 2
  • 8
  • 11
24
votes
5 answers

Is there Valgrind Memcheck like tool for windows to debug use after free errors?

Durring my work I regulary face rather common programming error - using some object which has already been freed. This invokes UB in C++. On linux, this kind of problems are usually resolved by using Valgrind tool Memcheck. From Memcheck…
ks1322
  • 33,961
  • 14
  • 109
  • 164