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
1
vote
0 answers

ffmpeg C API weird behaviour when running

I have a c++ project which I've been using for a while (on a stable build now), recently I had a new debian setup a few days ago and I've set everything up. I set up ffmpeg like I always do and some of my other projects which also depend on ffmpeg…
Turgut
  • 711
  • 3
  • 25
1
vote
2 answers

Memchk (valgrind) reporting inconsistent results in different docker hosts

I have a fairly robust CI test for a C++ library, these tests (around 50) run over the same docker image but in different machines. In one machine ("A") all the memcheck (valgrind) tests pass (i.e. no memory leaks). In the other ("B"), all tests…
alfC
  • 14,261
  • 4
  • 67
  • 118
1
vote
2 answers

Valgrind conditional jump ... error with PCRE2 JIT when reading from file

I have a very interesting problem. I'd like to use PCRE2, and its JIT function. The task is simple: read lines from a file, and find patterns. Here is the sample code: #include #include #define PCRE2_CODE_UNIT_WIDTH 8 #include…
airween
  • 6,203
  • 1
  • 14
  • 20
1
vote
2 answers

How to debug heap corruption on armv5

I am on linux on an embedded device. My architecture is armv5. My fairly large (~30kloc) has some kind of heap corruption that happens over time. I cannot run valgrind since my arch is not supported. I can only run a limited gdb since my app uses…
Eric
  • 19,525
  • 19
  • 84
  • 147
1
vote
1 answer

Is it possible to exactly find how much stack memory is consumed by a process by valgrind?

I have a project written in C language. I want to find stack memory(in the form of local variables etc) consumed by the process(realtime if possible or atleast max value). With massif, I am able to find exact heap consumption. But i am unable to…
Galaxo
  • 41
  • 5
1
vote
1 answer

Analyzing a OSx UI Application in Valgrind

I am new to OSX development, I had a question regarding running valgrind 3.6.1 on mac osx : 10.6.8 I was trying to analyze a GUI application using valgrind; However, From a console the GUI application cannot be directly launched and can be launched…
vine'th
  • 4,890
  • 2
  • 27
  • 27
1
vote
1 answer

Dynamic array allocation - valgrind conditional jump

I am trying to read a line from stdin in C and at the same time dynamically allocate memory for the string using the code snippet from below. The problem is that when I run this code, calling something like strlen(msg) results in an Conditional jump…
Shaxey
  • 13
  • 4
1
vote
1 answer

How to prevent conditional errors when freeing a linked list in C

I am creating a linked list in C with the syntax shown below struct int_list { int data; struct int_list *next; struct int_list *previous; } int_list; typedef struct { size_t active_length; struct int_list *head; struct…
Jon
  • 1,621
  • 5
  • 23
  • 46
1
vote
1 answer

Is it possible to get two different valgrind outputs on the same program? [threading in C]

I'm working on a C program that involves threading within the pthread library, as well as using some mallocs. I was troubleshooting my program and finally got it to where it runs with no memory leaks, and no errors.... sometimes When I run my…
1
vote
1 answer

Understanding uninitialised value(s) C

I was writing a tokenizer in C and although it works exactly as expected Valgrind throws uninitialized value(s) error. I'm perfectly aware of more than a solution for the code that will fix the problem. Tokenizer is compiled and put into a static…
Linnea117
  • 13
  • 3
1
vote
1 answer

Valgrind - many allocated bytes

Installed valgrind on my WSL and I was a bit confused. Problem: I get a lot of allocated bytes even though my program doesn't do anything. main.cpp: #include using namespace std; int main() { cout << "I'm testing valgrind!" <<…
1
vote
3 answers

Memory leak in the following C code

For the following sample of code there is memory leak. How can we prevent memory leak in the following case: 1 #include 2 #include 3 4 typedef struct sample_help { 5…
thetna
  • 6,903
  • 26
  • 79
  • 113
1
vote
0 answers

Memory leaks observed in getgrnam and getgrnam_r in linux

I'm trying to retrieve a linux group with some basic C code, but I encounter memory leaks with both getgrnam and getgrnam_r. The memory leaks only occurs when the linux group is missing in /etc/group. #ifndef _GNU_SOURCE #define…
Johan
  • 80
  • 6
1
vote
3 answers

How come it's possible to malloc() an infinite amount of memory in C?

I was trying to induce an ENOMEM error just to satisfy my own curiosity, so I decided to run the following code: #include #include int main(void) { double POS_INF = 1.0/0.0; char *s = malloc(POS_INF); } To my suprise,…
MathGeek
  • 141
  • 9
1
vote
1 answer

Memory deallocation in C

I've allocated a two-dimensional pointer array. I need to deallocate this pointer array w/o using array notation e.g., indices or offset values. main.c #include "practice.h" int main() { int **A, **B, **C; // declare arrays. initNumSpace(A,…
TheShanachie
  • 45
  • 10
1 2 3
99
100