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

Unstable output when using icc

I would like to report an intriguing bug I have. The piece of code below is supposed to print out 20 times "1.0". Instead, when compiling with icc (11.1) on my mac (snow leopard 10.6.8), I get unstable values (16 times "0.0" then 4 times "1.0"). I…
Waribiki
  • 113
  • 5
2
votes
1 answer

Is valgrind catching Qt 4.8 on Debian Wheezy leaking memory in minimalist app?

I've read several questions here where people run minimal Qt programs through valgrind, and post the results. The general verdict from looking over the output is "well, there are no actual leaks, it's just how Qt uses memory". However, what I'm…
2
votes
2 answers

Valgrind error in C++ memory leak checking

I'm trying to figure out Valgrind usage so I made a simple program but it seems Valgrind gives a strange error when I do dynamic mem allocation in class. My program is: class Valgrind_testclass { Valgrind_testclass *Obj; public: …
madu
  • 5,232
  • 14
  • 56
  • 96
2
votes
4 answers

trace variable change using valgrind and gdb

I have a program which SIGABRT after >5hrs of execution. It is most likely cause by memory leak after checking by valgrind, but I have problem trace down onto which variable actually causes this issue based on valgrind report (which simply contains…
twfx
  • 1,664
  • 9
  • 29
  • 56
2
votes
1 answer

Valgrind claiming I am using malloc when using new

Running Valgrind against an existing codebase, I am getting a lot of "Mismatched free / delete/ delete[]" errors. Many of them are a repeat of one problem: it claims that at line XXX a delete operation is being used, whereas at line YYY a malloc…
Keith Pinson
  • 7,835
  • 7
  • 61
  • 104
2
votes
2 answers

Helgrind for Windows?

Helgrind is a Valgrind tool for detecting synchronisation errors in C, C++ and Fortran programs that use the POSIX pthreads threading primitives. Anyone knows an equivalent tool for windows? After googling a bit I haven't found anything...
akappa
  • 10,220
  • 3
  • 39
  • 56
2
votes
1 answer

When I "make" valgrind, I got error

Andy@Macbook-Pro~/test/valgrind-3.6.1$ make make all-recursive Making all in include make[2]: Nothing to be done for `all'. Making all in VEX make all-am gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I../include -I../VEX/pub -DVGA_amd64=1 -DVGO_darwin=1…
David Degea
  • 1,378
  • 2
  • 12
  • 18
2
votes
1 answer

Valgrind Invalid read

Im getting several errors in valgrind referring to one section of my code. Basically I have a linked list of structs that acts as a queue. Here is my enqueue function: PcbPtr enqPcb(PcbPtr *headofQ, PcbPtr process){ PcbPtr c = *headofQ; …
Milk
  • 647
  • 1
  • 6
  • 18
2
votes
3 answers

Struct initialization leads to seg fault

The following code causes a segmentation fault. The executable is named './struct' #include #define VERSION_NUMBER_LEN 32 #define MAX_DESCRIPTION_COUNT 32 #define DESCRIPTION_LEN 128 int main(void) { struct foo { char…
Barton Chittenden
  • 4,238
  • 2
  • 27
  • 46
2
votes
1 answer

valgrind on mips

I have been trying to run valgrind on a MIPS machine. I successfully cross compiled valgrind and ran a few test from the test suite. But whenever valgrind tries to create a coredump, an assertion fails. Its from the file coredump-elf.c …
user414209
  • 361
  • 1
  • 5
  • 15
2
votes
3 answers

Cannot run make - created executables

I've written a simple program to run a towers of hanoi game (hanoi.c). The Makefile is very simple: CFLAGS=-Wall -g all: hanoi clean: rm -f hanoi I call make and it produces an executable hanoi, but when I try to run ./hanoi I only get the…
Ben S
  • 129
  • 1
  • 9
2
votes
1 answer

Am I loading my character array correctly?

I've stared at this so long that it's all starting to run together. So I'm getting a valgrind error: ==25468== Invalid write of size 4 ==25468== at 0x52CF64D: _IO_vfscanf (vfscanf.c:1857) ==25468== by 0x52D730A: __isoc99_fscanf…
Philip
  • 1,539
  • 14
  • 23
2
votes
2 answers

Failing to understand how to fix this memory leak

I'm creating a small solver that takes three arguments: number of hours, current time and true time. The program itself works fine, but there are memory leaks that I am unable to fix. Code: Inside my main: vector moves =…
Marcus Recck
  • 5,075
  • 2
  • 16
  • 26
2
votes
1 answer

C++: Error when copying from *std::shared_ptr

I have a function that returns a shared pointer to an object (it is difficult to include the MyObject definition because of many large dependencies): std::shared_ptr f(std::string params) { return std::shared_ptr(new…
user
  • 7,123
  • 7
  • 48
  • 90
2
votes
1 answer

Configuring valgrind for MPICH: wrong libmpi*.so file used

When running valgrind to detect errors in an mpi application, I get the following error: libmpi.so.0: cannot open shared object file: No such file or directory I found out the following: Valgrind documentation (section 4.9.1) states that "The MPI…
mort
  • 12,988
  • 14
  • 52
  • 97