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

Are memory addresses reported in valgrind absolute, physical addresses?

While running an MPI program with valgrind using mpirun -np 3 valgrind test, I noticed that the addresses of malloc/calloc'ed arrays are sometimes identical for different processes. This would lead me to believe that the addresses reported by…
ladc
  • 23
  • 2
2
votes
0 answers

Profiling a memory limited process with valgrind

I'm using the new_handler in C++ to try and free up some memory when an allocation fails. Is it possible to use massif in a way to profile this? I would like to see how much memory is actually freed by the handler and ideally have a detailed…
Flogo
  • 1,673
  • 4
  • 20
  • 33
2
votes
1 answer

is there anyone successfully use valgrind to check memory issues for iOS?

refer to http://alxsrg.com/?p=180 http://root42.blogspot.ru/2011/02/valgrind-checking-of-ios-programs.html and http://landonf.bikemonkey.org/code/iphone/iPhone_Simulator_Valgrind.20081224.html . I have tried in some situations, all fails. All I try…
fluke
  • 660
  • 8
  • 16
2
votes
0 answers

valgrind to detect memory leak in child process

I am using spawn-fcgi to start my application which take 3 parameters. when i try to use valgrind it gives no leak information. i am using this command valgrind --tool=memcheck --leak-check-full --trace-children=yes spawn-fcgi -s tempSocket ./myApp…
Anurag
  • 117
  • 1
  • 13
2
votes
1 answer

valgrind reports leaks for mysql_real_connect

I have the following code structure (The whole code is huge and I think this snippet is relevant to my problem), MYSQL_RES *res_set; MYSQL_ROW row; MYSQL *connect; int main() { connect=mysql_init(NULL); mysql_real_connect(connect, NULL, "root",…
Suvarna Pattayil
  • 5,136
  • 5
  • 32
  • 59
2
votes
1 answer

Memory Leak; when deleted exception raised

I'm writing a re-sizable array class (std::vector), as an exercise, using manual pointers (because I want to know how they work before I start using smart pointers). However, Valgrind reports a memory leak at the checkMax() function. template…
Sumanth
  • 71
  • 6
2
votes
1 answer

Callgrind does not see source in dynamically loaded SO

I'm attempting to run KCacheGrind on some results of callgrind. Basically the codebase is a plugin container that launches a shared object to run a specific function. Upon using Callgrind to profile this application, I can see the costs at the…
jluzwick
  • 2,005
  • 1
  • 15
  • 23
2
votes
4 answers

longest common subsequence: why is this wrong?

int lcs(char * A, char * B) { int m = strlen(A); int n = strlen(B); int *X = malloc(m * sizeof(int)); int *Y = malloc(n * sizeof(int)); int i; int j; for (i = m; i >= 0; i--) { for (j = n; j >= 0; j--) { if…
ithisa
  • 752
  • 1
  • 8
  • 25
2
votes
3 answers

Is there a data race in this code?

In this page, this sample code is written to explain how to use notify_one: #include #include #include #include std::condition_variable cv; std::mutex cv_m; int i = 0; bool done = false; void…
qdii
  • 12,505
  • 10
  • 59
  • 116
2
votes
1 answer

Valgrind fails when using setjmp and longjmp

I've been given an assignment so simulate a user-level thread library using signals, setjmp and longjmp c functions. Basically, the program include memory allocation for each 'thread', and using long jump and signals to simulate non-direct code…
Alonbs
  • 259
  • 1
  • 11
2
votes
6 answers

Valgrind: Deliberately cause segfault

This is a mad-hack, but I am trying to deliberately cause a segfault at a particular point in execution, so valgrind will give me a stack trace. If there is a better way to do this please tell me, but I would still be curious to know how to…
Joel
  • 11,431
  • 17
  • 62
  • 72
2
votes
1 answer

Is there a bug in the boost asio HTTP Server 3 example or boost bug?

boost library version 1.53 Debian Linux 6.0 ( Linux 2.6.32-5-amd64 on x86_64 ) It is hard to test own software when valgrind log contains lots of warnings. So with no changes I built the HTTP server3 example and run it under the Valgrind. Take a…
Andrey Volk
  • 3,513
  • 2
  • 17
  • 29
2
votes
1 answer

Invalid reads, writes and frees

I got a lot of write, read and free errors. I don't know where is mistake. If someone could help me out with this I'd be grateful. Here is log from valgrind: http://pastebin.com/TR4Ts73Y void deleteElement(element* node) { element* child; if (node…
user1824918
2
votes
2 answers

Eclipse does not find Valgrind

I installed Valgrind on SUSE Linux SLES 11SP2 under my home directory and added it to the path. I then installed eclipse Juno for C/C++ Service Release 2 Build id: 20130225-0426 and installed the Valgrind plugin. When I try to create a profile…
rmb
  • 31
  • 1
  • 2
2
votes
1 answer

Why doesn't valgrind massif report any function names or code references?

I have a program that is unexpectedly using a large amount of heap (about 3GB). I ran it through valgrind memcheck which reported no leaks, claiming that all the heap memory is still reachable. So I rebuilt all my libraries with debug options, and…
gubbins
  • 581
  • 4
  • 12