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

Interpreting Valgrind Memory Leak Summary Log

I am using Valgrind (a memory leak tool) to find a potential memory leak. It was run as such: $ valgrind --leak-check=full ./myApp The following was reported: ==9458== 15,007 bytes in 126 blocks are possibly lost in loss record 622 of 622 ==9458== …
code
  • 5,294
  • 16
  • 62
  • 113
2
votes
1 answer

Valgrind: Invalid write of size 1

I'm trying to create a block of memory on heap and copy some data to it using memcpy, but memcpy gives a segmentation fault. I feel I have allocated enough memory, but there seems to be an invalid write. I'm not able to reason why it happens. The…
user1124236
  • 453
  • 2
  • 7
  • 17
2
votes
1 answer

Why does a simple SDL program report memory leaks in Valgrind?

this program: #include #include /* * Lesson 0: Test to make sure SDL is setup properly */ int main(int argc, char** argv){ if (SDL_Init(SDL_INIT_EVERYTHING) != 0){ std::cout << "SDL_Init Error: " <<…
a797788
  • 21
  • 2
2
votes
1 answer

Valgrind and FCGI: How to free all memory correctly after use

Using this simple program: #include "fcgi_stdio.h" int main(void) { while(FCGI_Accept() >= 0) { } FCGI_Finish(); return(0); } I get this result from valgrind: Memcheck, a memory error detector Copyright (C) 2002-2013, and GNU GPL'd, by…
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
2
votes
2 answers

Valgrind heap summary understanding

I am running a code and I encounter the error as * glibc detected * /home/build/bin/../bin/OPENSUSE_12.2_X86_64/reader: corrupted double-linked list: 0x0000000003df6dc0 * I tried to re-run it by valgrind to know whether if any memory leak is…
user3619806
  • 31
  • 1
  • 1
  • 6
2
votes
0 answers

Abort error in C program when it reaches the end

I'm writing an orbit propagator in C, all the calculations work properly but the end is reached it suddenly aborts unexpectedly. [1] 67117 abort I tried to use Valgrind (which is only experimental on Mac, I know) to spot my error(s) and the…
la_
  • 51
  • 5
2
votes
2 answers

Valgrind hangs in pthread_spin_lock consuming 100% CPU

My C++ multi threaded application hangs in pthread_spin_lock in valgrind versions 3.8.0 and latest. But it is not happening in 3.6.0, 3.6.1 and 3.7.0. Anyone knows any workaround for this?
Sujith Gunawardhane
  • 1,251
  • 1
  • 10
  • 24
2
votes
1 answer

Valgrind Reports Invalid Realloc

I'm trying to backfill my knowledge of C memory management. I've come from a mostly scripting and managed background, and I want to learn more about C and C++. To that end I've been reading a few books, including one which included this example of…
Maurice Reeves
  • 1,572
  • 13
  • 19
2
votes
2 answers

mem-leak freeing g_strdup

I'm trying to free g_strdup but I'm not sure what I'm doing wrong. Using valgrind --tool=memcheck --leak-check=yes ./a.out I keep getting: ==4506== 40 bytes in 10 blocks are definitely lost in loss record 2 of 9 ==4506== at 0x4024C1C: malloc…
Mike
  • 33
  • 4
2
votes
1 answer

Valgrind C++ : Invalid Read Of Size 8

I've been having this problem while trying to create a generic Priority Queue. Valgrind gives me these errors : HEAP SUMMARY: ==39639== in use at exit: 0 bytes in 0 blocks ==39639== total heap usage: 22 allocs, 22 frees, 1,811 bytes…
2
votes
0 answers

How can I get address of variable using Valgrind API?

I've tried to modify Valgrind Lackey tool for getting addresses of array elements in my profiled program. I try to write simple memory access profiler, that stores in file two types of memory accesses: LOADs and STOREs. After getting that I want to…
2
votes
0 answers

Meaning of the grey dot in KCacheGrind

Doing some profiling I found KCacheGrind visualizing an arrow to a little grey dot. What does it mean?
techshack
  • 359
  • 2
  • 18
2
votes
1 answer

Finding performance issue that may be due to thread locking (possibly)

I've spent a little time running valgrind/callgrind to profile a server that does a lot of TCP/IP communications using many threads. After some time improving the performance, I realised that in this particular test scenario, the process is not CPU…
Peter S
  • 191
  • 1
  • 2
  • 10
2
votes
1 answer

Valgrind Memory Leak on malloc

I am working in a C project and I have created the following hash table implementation: typedef struct hash_record { char* key; char* value; struct hash_record* next; }hash_record; typedef struct hash_bucket { char* key; …
nick.katsip
  • 868
  • 3
  • 12
  • 32
2
votes
1 answer

How to make valgrind report only errors matching a rule

I know how to filter out errors based on suppression rules, but is it possible to make valgrind only show errors that match some criteria? Reverse suppression or kind of whitelisting if you will.
SnowFatal
  • 2,431
  • 1
  • 15
  • 12