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
362
votes
4 answers

How do I use valgrind to find memory leaks?

How do I use valgrind to find the memory leaks in a program? I am using Ubuntu 10.04 and I have a program a.c.
user484457
  • 4,301
  • 7
  • 21
  • 14
210
votes
38 answers

Is there a good Valgrind substitute for Windows?

I was looking into Valgrind to help improve my C coding/debugging when I discovered it is only for Linux - I have no other need or interest in moving my OS to Linux so I was wondering if there is a equally good program for Windows.
Drake
  • 1,938
  • 3
  • 18
  • 26
202
votes
2 answers

pinpointing "conditional jump or move depends on uninitialized value(s)" valgrind message

So I've been getting some mysterious uninitialized values message from valgrind and it's been quite the mystery as of where the bad value originated from. Seems that valgrind shows the place where the unitialised value ends up being used, but not…
kamziro
  • 7,882
  • 9
  • 55
  • 78
180
votes
5 answers

Still Reachable Leak detected by Valgrind

All the functions mentioned in this block are library functions. How can I rectify this memory leak? It is listed under the "Still reachable" category. (There are 4 more, which are very similar, but of varying sizes) 630 bytes in 1 blocks are…
user191776
167
votes
4 answers

How to redirect Valgrind's output to a file?

While working with Valgrind tool, i need to log the details produced by valgrind tool. How can I accomplish that? I tried something like, valgrind a.out | test and valgrind a.out > test It gave just the program's output and not the valgrind…
Dinesh
  • 16,014
  • 23
  • 80
  • 122
109
votes
12 answers

Yosemite and Valgrind

Can you tell me how to install valgrind on yosemite? When I try to install it i get " checking for the kernel version... unsupported (14.0.0) configure: error: Valgrind works on Darwin 10.x, 11.x, 12.x and 13.x (Mac OS X 10.6/7/8/9) " There is no…
Nikita Kozlov
  • 1,098
  • 2
  • 8
  • 12
107
votes
7 answers

Proper way to initialize C++ structs

Our code involves a POD (Plain Old Datastructure) struct (it is a basic c++ struct that has other structs and POD variables in it that needs to get initialized in the beginning.) Based one what I've read, it seems that: myStruct =…
KC3BZU
  • 1,224
  • 2
  • 11
  • 14
102
votes
1 answer

What Does This Valgrind Warning Mean? - warning set address range perms

When I was running my program against valgrind, I encountered the following warning. Warning: set address range perms: large range [0x4d59d040, 0x6159d040) (undefined) Warning: set address range perms: large range [0x194f7030, 0x2d4f7050)…
Jimmy Lu
  • 4,810
  • 7
  • 25
  • 30
89
votes
5 answers

How does valgrind work?

Can someone provide a quick top level explanation of how Valgrind works? An example: how does it know when memory is allocated and freed?
extraeee
  • 3,096
  • 5
  • 27
  • 28
86
votes
3 answers

Valgrind Massif tool output graphical interface?

I'm using Valgrind 3.3.1 with the Massif tool to profile the heap of a C++ application, and I'm wondering if there is a graphical tool to examine the textual outputfile file. Thanks for any suggestion.
puccio
  • 3,054
  • 8
  • 29
  • 20
74
votes
3 answers

PRE-2016 Valgrind: Memory still reachable with trivial program using

EDIT: I've voted to close this is it is now incorrect. In March 2016 Valgrind gained an option "--run-cxx-freeres=" (default is yes). This will call a libstdc++ function to free one-off allocations used for things like iostream. If you are…
sudo make install
  • 5,629
  • 3
  • 36
  • 48
74
votes
2 answers

How to use valgrind with python?

I am trying to memcheck a C python extension I am writing, but I'm having trouble setting up valgrind to work with python. I would really appreciate some advice. Just for context, this is Ubuntu 13.10, python 2.7.5+, and valgrind 3.8.1. As per…
Dejan Jovanović
  • 2,085
  • 1
  • 16
  • 22
69
votes
7 answers

Valgrind not showing line numbers in spite of -g flag (on Ubuntu 11.10/VirtualBox)

I'm following 'Learn C the Hard Way', specifically the chapter on Valgrind. This chapter gives you a deliberately wrong program to show how Valgrind works. When I run the exercise under Valgrind I do not get line numbers in my stack trace, just…
djb
  • 5,591
  • 5
  • 41
  • 47
67
votes
11 answers

How to install Valgrind on macOS Mojave(10.14) with Homebrew?

I tried to install Valgrind with brew install Valgrind and got : valgrind: This formula either does not compile or function as expected on macOS versions newer than Sierra due to an upstream incompatibility. Error: An unsatisfied requirement…
Katherine Elyon
  • 773
  • 1
  • 6
  • 5
65
votes
9 answers

Finding memory leaks in a C++ application with Visual Studio

In Linux, I have been using valgrind for checking if there are memory leaks in an application. What is the equivalent in Windows? Can this be done with Visual Studio 2010?
softwarematter
  • 28,015
  • 64
  • 169
  • 263
1
2 3
99 100