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

How to debug further based on Valgrind output

I have C/C++ code which is giving a segfault. It is compiled using gcc/g++ on a RH Linux Enterprise server. I used the Valgrind memory checker on the executable with: valgrind --tool=memcheck --leak-check=full --show-reachable=yes I get this as one…
goldenmean
  • 18,376
  • 54
  • 154
  • 211
2
votes
3 answers

Invalid read of size 1 in strstr() using valgrind

I'm inspecting some piece of code with valgrind and I get this error: ==7001== Invalid read of size 1 ==7001== at 0x402E21B: strstr (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==7001== by 0x8049742: replace_in_file…
Paul
  • 20,883
  • 7
  • 57
  • 74
2
votes
1 answer

When to call the QApplication destructor

So I realize that in fact I really do not need to do what I am about to explain but I am very picky about making sure my programs cleans up everything before exiting so I still want to do it... I have a QApplication that I connect a single shot…
David Mokon Bond
  • 1,576
  • 2
  • 18
  • 42
2
votes
3 answers

valgrind (memcheck) tool didnot detect memory-leak

I introduced memory errors with following piece of C code: #include #include int main(int argc, char** argv){ int i; int *a = (int *)malloc(sizeof(int) * 10); if (!a) return -1; /*malloc failed*/ for (i = 0; i < 11; i++){ …
2
votes
1 answer

How well does Valgrind handle threads and machine-level synchronization instructions?

I have a highly parallel Windows program that uses lots of threads, hand-coded machine synchronization instructions, and home-rolled parallel-safe storage allocators. Alas, the storage management has a hole (not a synchonization hole in the…
2
votes
1 answer

Is 64-bit version of Valgrind able to dig the memory issue of 32-bit program?

I have 64bit OS and Valgrind installed. And I need to check the memory problem of 32bit program right now. Valgrind can run and produce reprot. But I wonder whether the report generated by valgrind is able to deliver the correct information?
zzyang
  • 127
  • 4
2
votes
3 answers

glib: valgrind reporting 'still reachable' blocks after g_strsplit

I have a very simple piece of code: #include #include int main(int argc, char * argv[]) { const char * path = "/a/b/c/d/e/f/g/h/"; gchar ** parts = NULL; int i; parts = g_strsplit( (const gchar *) path, "/", 0 ); for…
Scott Frazer
  • 2,145
  • 2
  • 23
  • 36
2
votes
1 answer

Profile time spent

I am looking for some tools to profile where the time is spent. Have looked at oprofile, but that doesnt really give me what I need. I was looking at callgrind, specifically using the CALLGRIND_START_INSTRUMENTATION and…
Mark Lobo
  • 331
  • 2
  • 3
  • 9
1
vote
1 answer

running valgrind

I have not used valgrind before, but I need to use it to check memory leak. I ran the following command: G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind -v --tool=memcheck --leak-check=full --num-callers=40 --log-file=valgrind.log…
user1155299
  • 877
  • 5
  • 20
  • 29
1
vote
2 answers

Tracking memory usage of piped commands with valgrind

I have a couple processes running a tool I've written that are joined by pipes, and I would like to measure their collected memory usage with valgrind. So far, I have tried something like: $ valgrind tool=massif trace-children=yes…
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
1
vote
1 answer

How to do find memory leaks for Android application with valgrind

I wanna use valgrind to find memory leaks on android platform ,especially,for the java code. Although i know the tools usually running for C/C++ code. With ICS , the valgrind can be compiled smoothlty, but I can not run successful with a java…
1
vote
1 answer

Cleaning up function interposition with dlsym

As a malloc wrapper, I use this classical snippet of code: #define _GNU_SOURCE #include #include #include void* malloc(size_t size) { static void* (*real_malloc)(size_t) = NULL; if (!real_malloc) …
ziu
  • 2,634
  • 2
  • 24
  • 39
1
vote
1 answer

Invalid read of size 4

Hello there I have the following code: struct Edge { Node * nodeA, * nodeB; int weight; }; . . This is typedef'd to simply Edge elsewhere. . . int cmp(const void *b, const void *a) { Edge * e1 = (Edge*)a; Edge * e2 = (Edge*)b; …
user1256230
  • 13
  • 1
  • 4
1
vote
1 answer

Valgrind: Invaild read of size 8

I have been working on an open source project for awhile, http://gtkworkbook.sourceforge.net/, and recently ran into an issue that just seems like I am going in circles. I'm pretty sure there is a heap problem but I have been looking at this code…
John Bellone
  • 1,351
  • 1
  • 16
  • 29
1
vote
1 answer

Exception thrown during valgrind execution but not when program is called directly

I am running in a very odd problem and I understand that it may be hard to diagnose from afar. But any hints would be helpful. Having said this, here's my problem: When I run valgrind to execute my program, an exception is thrown. However, when I…
Achim
  • 33
  • 1
  • 3