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

Segfault on `mkl_malloc`

Context I want to use Intel's MKL library to create an array and then do various stuff with it. However, it segfaults on mkl_malloc. Problem I am trying to run the following program. On running it, I get a segfault at the specified line. The problem…
Unapiedra
  • 15,037
  • 12
  • 64
  • 93
2
votes
2 answers

How to debug double delete in QNetworkReply::deleteLater()

I have an application written in C++ & Qt that does a lot of network requests. The basic outline of my code is below: { QNetworkReply* reply = networkAccessManager().get( QNetworkRequest( url ) ); assert( reply ); connect( reply,…
Stefan
  • 1,539
  • 13
  • 11
2
votes
1 answer

icu::Calendar::createInstance() leaks memory

Here's a test program which leaks (on Ubuntu 10.04, ICU 4.2): #include #include int main() { TimeZone* tz = TimeZone::createTimeZone("Asia/Pyongyang"); UErrorCode status = U_ZERO_ERROR; Calendar* cal…
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
2
votes
1 answer

Is there a reasonable replacement for callgrind?

I have a program with an inner loop that needs to be very very fast due to the number of iterations it performs. To profile this code I have been using valgrind/callgrind. I find it to be a wonderful tool. Unfortunately my efforts at optimizations…
James Matta
  • 1,562
  • 16
  • 37
2
votes
1 answer

Valgrind: How to understand exactly when I lose control of a pointer to a memory location

I am using the valgrind's tool memcheck together with GDB trying to track down a memory leak in my C code. Valgrind found where the memory was allocated but the pointer to this memory is tossed around a lot in the code before it is free'd. About 99…
Olppah
  • 790
  • 1
  • 10
  • 21
2
votes
1 answer

Don't see line numbers using Valgrind inside Ubuntu (Vagrant+Virtualbox)

I am currently reading and fallowing along the "Learn C The Hard Way"-book. On exercise 4 I have to install Valgrind. I first did this locally on my Macbook running Maverick, but I received a warning that Valgrind might not work 100%. So now I tried…
Ilyes512
  • 2,627
  • 5
  • 23
  • 27
2
votes
3 answers

Checking fftw3 with valgrind

In one step of my program I need to convolve an image. To do that I am using the functions provided by fftw3. When I run valgrind on my program I get this stack trace. My function is called convolve and it runs fftw3's fftw_plan_dft_r2c_2d two times…
makhlaghi
  • 3,856
  • 6
  • 27
  • 34
2
votes
2 answers

Valgrind reports uninitialized value when calling wcstombs

I have stumbled on a Valgrind report that I can't manage to fix by myself. I have a function that reads a Microsoft "unicode" string (a series of two-byte aligned wchar_t prefixed by a size) from a file. A sample file might look like this: 0004 0041…
executifs
  • 1,138
  • 1
  • 9
  • 23
2
votes
1 answer

Valgrind Memcheck Output

I'm using valgrind to find memory leak on my system, and I received this output ==9697== Memcheck, a memory error detector ==9697== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. ==9697== Using Valgrind-3.7.0 and LibVEX; rerun with…
Vitor Villar
  • 1,855
  • 18
  • 35
2
votes
1 answer

Valgrind: Invalid read / write of size 1

I am trying to build a very basic web server using C. I have solved all of the problems reported by valgrind except this one. This is the relevant piece of code that causes it. I have added x>> to the lines that valgrind suggests: /* Set the…
Vlad Schnakovszki
  • 8,434
  • 6
  • 80
  • 114
2
votes
1 answer

Is QMap generating memory leaks?

as a newbie valgrind user I can't figure out the reason why it outputs the following message 40 bytes in 1 blocks are definitely lost in loss the offending code lines are the following: void KukaDevice::_init() { …
ragingbit
  • 220
  • 1
  • 3
  • 9
2
votes
3 answers

Limiting resource usage for debugging an application on linux

I have a C/C++ application that crashes only under heavy loads. I normally use valgrind and gprof to debug memory leaks and profiling issues. Failure rate is like about 100 in a million runs. This is consistent. Rather than reproduce the traffic to…
Sridhar Iyer
  • 2,772
  • 1
  • 21
  • 28
2
votes
3 answers

Stack in C: why do i have memory leaks?

just revising C here. I just ran valgrind and it turns out i have memory leaks in my program, even though i free the memory i allocate. What am i missing? stack.c: #include #include #include "stack.h" struct node { int…
chuckfinley
  • 2,577
  • 10
  • 32
  • 42
2
votes
2 answers

memory leak strtok & atof

int fromVectoEigen(vector & source, double ** & array, int & n) { cout<<"n:"<= 0 ; j--) // iterate through each line { string mystring = source.back(); // take last…
dieHellste
  • 252
  • 1
  • 2
  • 11
2
votes
1 answer

program crashing under gdb but runs fine under valgrind

My program on the command line is crashing with a segmentation fault. I limited the stack size and ran the program again and generated the core file to investigate the location of the problem. Then under gdb I tried to investigate the reason but…
Umut Tabak
  • 1,862
  • 4
  • 26
  • 41