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
40
votes
1 answer

Valgrind: can possibly lost be treated as definitely lost?

Can I treat the output of a Valgrind memcheck, "possibly lost" as "definitely lost"? Possibly lost, or “dubious”: A pointer to the interior of the block is found. The pointer might originally have pointed to the start and have been moved along, or…
webminal.org
  • 44,948
  • 37
  • 94
  • 125
40
votes
3 answers

Helgrind (Valgrind) and OpenMP (C): avoiding false positives?

The documentation for the Valgrind thread error detection tool Helgrind, found here warns that, if you use GCC to compile your OpenMP code, GCC's OpenMP runtime library (libgomp.so) will cause a chaos of false positive reports of data races, because…
Amittai Aviram
  • 2,270
  • 3
  • 25
  • 32
39
votes
3 answers

valgrind - Address ---- is 0 bytes after a block of size 8 alloc'd

First, I know similar questions have been asked. However, I'd like to have a more general simple question with really primitive C data types. So here it is. In main.c I call a function to populate those string: int main (int argc, char *argv[]){ …
oz123
  • 27,559
  • 27
  • 125
  • 187
39
votes
0 answers

Difference between gdb, valgrind, strace, ltrace and apport

I'm looking for the difference between the following debugging tools. What are those? E: On the off chance that somebody stumbles in here and was wondering about the same thing the "differences" are (shortened from the man pages): GDB Allows you to…
Det
  • 3,640
  • 5
  • 20
  • 27
38
votes
2 answers

How to install Valgrind on macOS Catalina (10.15) with Homebrew?

I tried to install Valgrind with the command "brew install valgrind" and I get a message that says: "valgrind: This formula either does not compile or function as expected on macOS versions newer than Sierra due to an upstream incompatibility.…
38
votes
1 answer

How do I add valgrind tests to my cmake "test" target

I run unit tests by building with ninja and then running ninja test from my build tree: cmake -G Ninja /source/tree ninja ninja test However, to run valgrind I need to run it manually: valgrind rel/path/to/test I'd like valgrind to run…
quant
  • 21,507
  • 32
  • 115
  • 211
37
votes
7 answers

Windows Callgrind results browser, alternative to KCacheGrind

Is there any tool, other than KCacheGrind, being able to view callgrind results? Preferably for Windows platform?
anon
37
votes
2 answers

Is it overkill to run the unit test with Valgrind?

Just some days ago I started looking into a unit test framework called check, and I intend to run the test on c code under Linux. Now check and some well designed code and some test code can help me to verify that the basic functionality is…
Johan
  • 20,067
  • 28
  • 92
  • 110
37
votes
3 answers

How do you tell Valgrind to completely suppress a particular .so file?

I'm trying to use Valgrind on a program that I'm working on, but Valgrind generates a bunch of errors for one of the libraries that I'm using. I'd like to be able to tell it to suppress all errors which involve that library. The closest rule that I…
Jonathan M Davis
  • 37,181
  • 17
  • 72
  • 102
35
votes
3 answers

C free(): invalid pointer

I am teaching myself C. My goal is to make a C function that just walks a query string and splits on the ampersand and the equals sign. I am getting stuck on this error from Valgrind. ==5411== Invalid free() / delete / delete[] / realloc() ==5411== …
Dan
  • 2,209
  • 3
  • 23
  • 44
34
votes
6 answers

How to build and install Valgrind on Mac?

I am on Mac OS X using codeblocks 10.05 I downloaded Valgrind, and extracted a folder. I am completely lost from there, and have no idea how to build it. I do not know ANY terminal/console commands and am generally new to programming, so I have no…
user1017485
  • 679
  • 1
  • 8
  • 16
34
votes
1 answer

Terminate process running inside valgrind

Killing the valgrind process itself leaves no report on the inner process' execution. Is it possible to send a terminate signal to a process running inside valgrind?
Antonio Pérez
  • 6,702
  • 4
  • 36
  • 61
32
votes
5 answers

Why does valgrind say basic SDL program is leaking memory?

Here is the SDL program: #include int main(int argc, char** argv){ SDL_Init(SDL_INIT_VIDEO); SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE); SDL_Quit(); return 0; } Compiled with the command: g++ -o test…
Christian
  • 1,111
  • 2
  • 13
  • 15
32
votes
1 answer

How to get in script whether valgrind found memory leaks?

I am running valgrind in a bash script, and directing the valgrind's output to a file. Like this : valgrind --leak-check=full --show-reachable=yes --xml=yes --xml-file=unit_tests_valgrind.out.xml ./unit_tests_runner The RET_VALUE=$? is going to put…
BЈовић
  • 62,405
  • 41
  • 173
  • 273
31
votes
5 answers

valgrind memory leak errors when using pthread_create

I'm writing a program using the pthread library. When I run my program with the command valgrind --leak-check=full, I get the following errors description: ==11784== ==11784== **HEAP SUMMARY:** ==11784== in use at exit: 4,952 bytes in 18…
lim
  • 371
  • 1
  • 4
  • 4