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
24
votes
2 answers

Valgrind and Java

I want to use Valgrind 3.7.0 to find memory leaks in my Java native code. I'm using jdk1.6.0._29. To do that, I have to set the --trace-children=yes flag. Setting that flag, I no longer can run valgrind on any java application, even a command…
RezaPlusPlus
  • 545
  • 1
  • 8
  • 18
24
votes
2 answers

How to start an android app with valgrind

I've been searching for the last week trying to find an answer to this question. How do I start an Android app with valgrind? I know I can start an app with the 'am' command, but it starts the app and exits. I'm writing an app that uses the NDK for…
Scott
  • 5,135
  • 12
  • 57
  • 74
24
votes
2 answers

Valgrind reports memory 'possibly lost' when using glib data types

I'm developing a library using a number of glib datastructures (GHashTable, GSList etc.). I've been checking my code frequently for memory leaks using valgrind. Most of the issues valgrind points out are quite easy to fix, however there's a few that…
tomger
  • 539
  • 8
  • 16
24
votes
5 answers

Valgrind vs Purify

Which one is better on Linux? Valgrind or Purify What is your opinion of using them?
godfryd
  • 537
  • 1
  • 4
  • 12
23
votes
8 answers

Lightweight memory leak debugging on linux

I looked for existing answers first and saw that Valgrind is everyone’s favorite tool for memory leak debugging on linux. Unfortunately Valgrind does not seem to work for my purposes. I will try to explain why. Constraints: The leak reproduces only…
glagolig
  • 1,100
  • 1
  • 12
  • 28
23
votes
3 answers

How to undo strip - i.e. add symbols back to stripped binary

I have a stripped binary and symbol-file. Is it possible to add the symbols back to binary and create an unstripped binary. My use-case is using this binary w/ valgrind.
cached
  • 569
  • 1
  • 7
  • 14
23
votes
2 answers

Valgrind: Invalid read of size 1

I'm having an issue with valgrind: This is my program (well the main part where the errors appear): int main() { char comanda[N]; .... char *p; while( fgets(comanda,100,stdin)!=NULL) { p=strtok(comanda," \n"); if…
user1934103
  • 231
  • 1
  • 2
  • 3
23
votes
2 answers

Valgrind: invalid read of size 4 -> sigsegv, works fine without valgrind and in visual studio

I have implemented a compression algorithm (using huffman coding) which uses a priority queue of nodes (a struct i defined). Now, when i just run the code in linux or in visual studio, everything works fine. When I check for memory leaks in visual…
HaS
  • 391
  • 2
  • 3
  • 10
23
votes
4 answers

make fails while installing Valgrind

I'm trying to install Valgrind on a Mac with Snow Leopard but am getting an error. This is what I'm typing into Terminal. $ curl -O http://valgrind.org/downloads/valgrind-3.8.1.tar.bz2 $ md5sum valgrind-3.8.1.tar.bz2 $ tar -xjvf…
Jack Stout
  • 1,265
  • 3
  • 12
  • 25
22
votes
1 answer

Understanding the amount of memory c++ is allocating

I'm trying to develop a better understanding of the amount of memory that is allocated on the heap in c++. I've written a small test program which basically does nothing else than fill a number of 2D vectors. I'm running this on a linux 64bit VM and…
Gio
  • 3,242
  • 1
  • 25
  • 53
22
votes
3 answers

Valgrind gives an error for nearly everything (Warning: client switching stacks?)

I'm corrupting memory somehow because my program crashes without error at random places. I'm using valgrind with --leak-check=full, compiling with -O0 -g, and the very first problem it detects is the first line in int main() cout << "reading file"…
user1382306
22
votes
5 answers

valgrind doesn't accept newest version of glibc

Valgrind doesn't like glibc 2.15: checking the GLIBC_VERSION version... unsupported version 2.15 configure: error: Valgrind requires glibc version 2.2 - 2.14 How can I deal with this? do I have to downgrade glibc? I'm working on Ubuntu 12.04 if…
talloaktrees
  • 3,508
  • 6
  • 28
  • 43
22
votes
1 answer

Can valgrind be used along with Cygwin?

I am building source on Windows using Cygwin, I need to find places with memory leaks and possible memory leaks. I know about Valgrind used for memory leak detection in Linux. Can Valgrind be used along with Cygwin so that it works in a Windows…
akashbhatia
  • 332
  • 1
  • 5
  • 11
21
votes
4 answers

Alternative to valgrind (memcheck) for finding leaks on linux?

I have a linux x86 application that makes use of various third-party shared-object libraries. I suspect these libraries are leaking memory (since it can't possibly be my code ;-) I tried the trusty valgrind, but it died a horrible death because one…
jhfrontz
  • 1,165
  • 4
  • 19
  • 31
21
votes
1 answer

Is there a tool to examine the difference of two callgrind/valgrind profiles?

I'm trying to understand how a program's performance changes when run with different options—I have a factor of 1.8 I'd like to explain. I've been doing profiling with [valgrind]'s callgrind tool and using kcachegrind to visualize the results. But…
Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533