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
1 answer

sequence of page references by a program

How can I have the sequence of pages referenced by a program using Valgrid or any other tool? I don't want the total count of hits or misses but the exact list of page numbers ordered by access. I want to use this sequence as the input of a…
1
vote
1 answer

Valgrind is not instrumenting: "total heap usage: 0 allocs, 0 frees, 0 bytes allocated"

Even after introducing an intentional memory leak valgrind shows: ==13483== HEAP SUMMARY: ==13483== in use at exit: 0 bytes in 0 blocks ==13483== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==13483== ==13483== All heap blocks were…
Matt Chambers
  • 2,229
  • 1
  • 25
  • 43
1
vote
2 answers

What does this error mean in Valgrind

When I run my program, I get segmentation fault, so I decided to check it through Valgrind. When I did, I got the following message from Valgrind. And I get the error when I use the code described here. Any idea what is going on here? ==21471==…
MetallicPriest
  • 29,191
  • 52
  • 200
  • 356
1
vote
1 answer

Valgrind invalid write error with array of pointers to structs

I'm getting an error (well, a ton of errors actually) from valgrind that I'm having trouble sorting out. I'm using this code to declare a struct: struct HashTableT { HashFuncT hashFunc; // array of SortedList's SortedListPtr* arrayPtr; }; typedef…
jobrien929
  • 155
  • 1
  • 5
1
vote
3 answers

Monitoring of a memory allocation

I'm developing on Linux/g++ and uses valgrind to verify memory usage. My question is: How do I know where there is an allocation of memory in my application (including system libraries)? May be valgrind provides this functionality, or some similar…
Andrii
  • 1,788
  • 11
  • 20
1
vote
2 answers

Segmentation fault with valgrind

I'm just starting with C programming (following along with 'C The Hard Way') - anytime I try to run valgrind I'm getting Segmentation fault in terminal right off the bat. I've installed and reinstalled valgrind Any suggestions here?
Tony Ciccarone
  • 132
  • 1
  • 7
1
vote
1 answer

Valgrind output Understanding

==20420== ==20420== HEAP SUMMARY: ==20420== in use at exit: 0 bytes in 1 blocks ==20420== total heap usage: 1 allocs, 0 frees, 0 bytes allocated ==20420== ==20420== Searching for pointers to 1 not-freed blocks ==20420== Checked 48,492…
Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222
1
vote
1 answer

free() on char* recognized as invalid by valgrind

I am attempting to free char* pointers that exist within a char** array, but valgrind is determining this operation as invalid. Here is a simple example of what I'm doing: struct building{ int propertyPrice; int totalArea; char**…
1
vote
1 answer

Valgrind illegal hardware instruction with Zig

I'm trying to debug the memory using Valgrind for a simple Zig code that leaks memory. This is the code I'm using const std = @import("std"); const Point = struct { x: i32, y: i32, }; pub fn main() !void { const allocator =…
Isky
  • 1,328
  • 2
  • 14
  • 33
1
vote
0 answers

CS50 PSET 4 "Speller" - Having issues freeing allocated memory

I'm programming a spellchecker per CS50's Week 4 problem set, but I ran into an issue. I am leaking memory. :) dictionary.c exists :) speller compiles :) handles most basic words properly :) handles min length (1-char) words :) handles max length…
nzo
  • 11
  • 2
1
vote
2 answers

Why does Valgrind not like my usage of glutCreateWindow?

I'm using the following code... 169: const char *title = Title.c_str(); 170: glutCreateWindow(title); ... Valgrind gives me the following ... ==28841== Conditional jump or move depends on uninitialised value(s) ==28841== at 0x6FF7A4C: (within…
Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
1
vote
0 answers

Valgrind Memory error detection on just call to Py_Initialize() and nothing else

I am adding my python code into c++ for making an wrapper to c api that can be later used inside cpp as library and everything is working fine but for except one thing that is memory errors. See bellow code. #include "Python.h" #include…
1
vote
1 answer

Incorrect joint work of Valgrind with GDB

I'm trying to connect Valgrind to GDB. I've written a test code: #include int main() { int x, i; for (i=0; i < 10; i++) { if (x < 10) printf("First\n"); else printf("Second\n"); x =…
Fyodor
  • 25
  • 5
1
vote
1 answer

Heap memory usage for Openssl

I have a simple HTTPS server implemented with Openssl library in C. The heap usage seems huge for a single connection. The following are some objects that might take big heap space: char readbuffer[8192] SSL_CTX SSL Is this normal? Is there a tool…
Wei Shi
  • 4,945
  • 8
  • 49
  • 73
1
vote
1 answer

CS50 Speller Pset working with valgrind but not separately

I'm doing the Pset5 of CS50, "speller", where you have to create a spelling checking program that loads a dictionary into memory, and hashes the words into a hash table. Then it reads a text file, compares it to the dictionary word for word, and…
user75470
  • 45
  • 5