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
65
votes
3 answers

Is it possible to make valgrind ignore certain libraries?

Or preferably all of them instead of just my code? My program uses Gtk, Loudmouth and few other things, and these two (and some behind them, libgcrypto, libssl) are causing so many errors themselves that I'm unable to detect my own. Is it possible…
tadzik
  • 1,330
  • 1
  • 9
  • 12
60
votes
4 answers

How to use the addr2line command in Linux?

I am trying to use addr2line command in Unix but everytime it is giving the same output as ??:0. I am giving command as addr2line -e a.out 0x4005BDC . I got this address while running this a.out executable with valgrind tool to find the memory…
Prak
  • 979
  • 3
  • 12
  • 17
60
votes
4 answers

Finding the cause of a memory leak in Ruby

I've discovered a memory leak in my Rails code - that is to say, I've found what code leaks but not why it leaks. I've reduced it down to a test case that doesn't require Rails: require 'csspool' require 'ruby-mass' def report puts 'Memory ' +…
jb_314
  • 1,373
  • 2
  • 17
  • 28
59
votes
5 answers

Valgrind reporting a segment overflow

When running my program with valgrind / callgrind I get the following message a lot: ==21734== brk segment overflow in thread #1: can't grow to 0x4a39000 (with different addresses) Note that it is not preceded by a stack overflow message. I can't…
Tim Kuipers
  • 1,705
  • 2
  • 16
  • 26
58
votes
5 answers

Why is there a memory leak in this program and how can I solve it, given the constraints (using malloc and free for objects containing std::string)?

This is a minimal working example for the problem I am facing in my real code. #include namespace Test1 { static const std::string MSG1="Something really big message"; } struct Person{ std::string name; }; int main() { auto…
55
votes
24 answers

What tools do you use to develop C++ applications on Linux?

I develop C++ applications in a Linux environment. The tools I use every day include Eclipse with the CDT plugin, gdb and valgrind. What tools do other people use? Is there anything out there for Linux that rivals the slickness of Microsoft Visual…
Clayton
  • 6,089
  • 10
  • 44
  • 47
53
votes
2 answers

Memory/Address Sanitizer vs Valgrind

I want some tool to diagnose use-after-free bugs and uninitialized bugs. I am considering Sanitizer(Memory and/or Address) and Valgrind. But I have very little idea about their advantages and disadvantages. Can anyone tell the main features,…
kayas
  • 703
  • 1
  • 5
  • 14
49
votes
4 answers

How to profile memory usage?

I am aware of Valgrind, but it just detects memory management issues. What I am searching is a tool that gives me an overview, which parts of my program do consume how much memory. A graphical representation with e.g. a tree map (as KCachegrind does…
math
  • 8,514
  • 10
  • 53
  • 61
47
votes
6 answers

pthread_exit vs. return

I have a joinable pthread runner function defined as below: void *sumOfProducts(void *param) { ... pthread_exit(0); } This thread is supposed to join the main thread. Whenever I ran my program through Valgrind I would get the following leaks: LEAK…
user191776
46
votes
5 answers

Valgrind on macOS Sierra

I following this guide: valgrind installation guide After I have downloading the package, and I have run the sh script, but when I launch the make install command, it couldn't create the folder because it don't have the permission (even though I…
th3g3ntl3man
  • 1,926
  • 5
  • 29
  • 50
45
votes
10 answers

Memory leak C++

I just wrote a code in C++ which does some string manipulation, but when I ran valgrind over, it shows some possible memory leaks. Debugging the code to granular level I wrote a simple C++ program looking…
Global Warrior
  • 5,050
  • 9
  • 45
  • 75
45
votes
1 answer

How do I tell valgrind to memcheck forked processes?

I have a process x that I want to check for leaks with valgrind. The problem is that x is run by y, and y in turn is run by z. I can't run x standalone because y and z setup the environment for x, such as environment variables, command line…
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
42
votes
3 answers

Are there any alternatives to valgrind on Mac OS X Mountain Lion and Mavericks to detect memory leaks for C/C++ applications?

I used to use valgrind to detect memory leaks for my C/C++ applications on Mac OS X 10.6 (Snow Leopard) and 10.7 (Lion), but I find it's not supported on recent releases like 10.8 (Mountain Lion) and 10.9 (Mavericks) when I upgraded my OS. Is there…
hago
  • 1,700
  • 2
  • 16
  • 18
41
votes
3 answers

How can I use valgrind with Python C++ extensions?

I have Python extensions implemented on C++ classes. I don't have a C++ target to run valgrind with. I want to use valgrind for memory check. Can I use valgrind with Python?
neuron
  • 619
  • 2
  • 7
  • 13
40
votes
3 answers

use valgrind to know time(in seconds) spent in each function

is there any extension of valgrind, that can be used in the command window, that would help me know the time, in seconds, spent in each function in my C code? thanks =)
Syntax_Error
  • 5,964
  • 15
  • 53
  • 73