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

Valgrind output with address and question marks?

I have just receive an output from valgrind that I do not quite understand: ==20290== Invalid read of size 1 ==20290== at 0x8C1D678: ??? ==20290== by 0x5D74C47: ??? ==20290== Address 0xee818c7d is not stack'd, malloc'd or (recently)…
Eugene B
  • 995
  • 2
  • 12
  • 27
2
votes
1 answer

valgrind vgdb with gdb in emacs

I'm trying to use valgrind vgdb with command: valgrind --vgdb-error=0 ./a.out [args]. when I run target remote | /usr/lib64/valgrind/../../bin/vgdb in emacs gdb I get Non-stop mode requested, but remote does not support non-stop error. The gdb…
Sirttas
  • 160
  • 12
2
votes
1 answer

Unknown intermittent crash due dragging and dropping in Qt

I've been trying to find this bug for over a day now and I'm starting to go mad... I have re-written and closely examined the code for dragging and dropping to no avail. It occurs in the main Qt event loop a.exec() with the stack trace from valgrind…
robby987
  • 827
  • 1
  • 9
  • 25
2
votes
2 answers

Compiling Valgrind with MPI support

I'm trying to install Valgrind with full support for MPI under Linux. According to the Valgrind documentation. I should compile with MPI already installed, but according to both the MPICH and OpenMPI documentation, I should compile with Valgrind…
user787267
  • 2,550
  • 1
  • 23
  • 32
2
votes
1 answer

jenkins valgrind executable options missing

I've got a jenkins CI installed with the valgrind plugin. There is one very important thing missing there: you cannot set executable options. I can set parameters, but if I want to call valgrind my_executable -opt my_option_value the plugin will…
ducin
  • 25,621
  • 41
  • 157
  • 256
2
votes
1 answer

Valgrind cannot locate stack allocation for uninitialised data

I have a a single error when I run my program through valgrind. The problem is that it wont tell me where the uninitialised bytes were allocated: ==22141== Syscall param write(buf) points to uninitialised byte(s) ==22141== at 0x5B68900:…
Matthew Mitchell
  • 5,293
  • 14
  • 70
  • 122
2
votes
1 answer

free(): invalid next size (normal) on fclose. But not when Valgrind runs

The code below breaks on the fclose() call. void output_gauss_transform(char* filename, char* mode, double** T, double shift, int len) { FILE* fp; printf("Outputting gauss transform to %s.\n", filename); if…
heuristicus
  • 1,130
  • 12
  • 31
2
votes
2 answers

Valrind reports "still reachable" in empyt function

I'm using valgrind to check about the memory usage of my C application. After the first tests valgrind reports: "still reachable: 2,248 bytes in 1 blocks". I checked the code but I was not able to find the problem at mere sight. So I started to…
user1274605
  • 405
  • 2
  • 6
  • 17
2
votes
2 answers

How does Valgrind estimate the cost of a function?

I am trying to figure out how does program profiling work. I am using Valgrind. My first question is: What does the cost of a function mean for Valgrind? Is is time? From what I read, it seems that Valgrind runs the program on a virtual machine…
Martin Drozdik
  • 12,742
  • 22
  • 81
  • 146
2
votes
1 answer

Invalid Write with strcpy

I have been programming for a while but I am new to C. I have this linked list implementation in ansi C that I need to test. I have narrowed the problem down to an issue with an invalid write. I ran the code through Valgrind and received the…
user1935333
  • 21
  • 1
  • 5
2
votes
2 answers

Valgrind has reported "memory leak" when I compiled my program with "-pg" enabled?

I've get a memory leak reported by Valgrind with -pg enabled when compiling the following simple code. #include #include #define BOOST_FILESYSTEM_VERSION 3 using boost::filesystem::path; using namespace std; int…
macpaul
  • 21
  • 1
2
votes
1 answer

libxml2: xmlNewTextWriterFilename leaks

The following code compiles correctly and valgrind reports no leaks: # include # include int main(void) { xmlTextWriterPtr XMLWriter = xmlNewTextWriterFilename("example.xml", 0); …
Witiko
  • 3,167
  • 3
  • 25
  • 43
2
votes
3 answers

Investigating a class in C++ software at runtime

I have a C++ based program up and running, my problem is that I would like to know: what are the top10, top5, topX methods that are called the most what are the heaviest classes for computation or what threads require the maximum clock cycles it's…
user1849534
  • 2,329
  • 4
  • 18
  • 20
2
votes
1 answer

Compile Valgrind for armv5

everyone. I got some problems while cross compile valgrind for armv5(arm926ej-s). I can figure out some of them, but there is one I cannot solve. I will write these problems: Valgrind don't support armv5 in configure, I instead armv7*) with…
Bin Wang
  • 2,697
  • 2
  • 24
  • 34
2
votes
3 answers

Program with realloc behave differently in Valgrind

I wrote a function to read a string with fgets that uses realloc() to make the buffer grow when needed: char * read_string(char * message){ printf("%s", message); size_t buffsize = MIN_BUFFER; char *buffer = malloc(buffsize); if…
nh2
  • 45
  • 6