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
2 answers

Stack overflow / Seg fault when dealing with random numbers

I'm creating a little tic tac toe game and I generate the computer's move randomly using this function: //Generates the computer's move randomly void tictactoe::getComputerMove( char** b ) { int rand1,rand2; //Generate two random numbers …
Joshua
  • 4,270
  • 10
  • 42
  • 62
1
vote
3 answers

vector pointer causing valgrind memory leak

I'm trying to learn C++ and valgrind. So I wrote the following code to test it out. But I get some memory leaks. Can anyone explain what's causing the memory leak? Thanks in advance. #include #include using namespace std; class…
oli ten
  • 23
  • 3
1
vote
1 answer

Tracking down Valgrind 40 bytes in 1 blocks are definitely lost in loss record

I am new to Valgrind (and my C/C++ is rusty) and I am getting an error: 40 bytes in 1 blocks are definitely lost in loss record 35 of 111 ==26930== at 0x4C275C2: operator new(unsigned long) (vg_replace_malloc.c:261) ==26930== by 0x5EFAFDB:…
chrislovecnm
  • 2,549
  • 3
  • 20
  • 36
1
vote
3 answers

Unitialised value(s) using valgrind

I'm running valgrind and I'm getting the following error.. before I made a backup I fixed it but now I don't remember how. Error was generated by malloc but I can't find the error in the code >Insert password for admin: ==5720== Conditional jump or…
roccocullo
  • 178
  • 11
1
vote
4 answers

Valgrind not showing errors with array copy?

Consider the following pretty simple C++ code: #include #include using namespace std; int main() { int a[7] = {1, 2, 3, 4, 5, 6, 7}; int b[7]; copy(a, a+7, b); for (int i=0; i<8; ++i) cout << b[i] << endl; } Now…
Fanatic23
  • 3,378
  • 2
  • 28
  • 51
1
vote
1 answer

Integrate valgrind in qt creator

I'm wondering why I can't use the valgrind analyizer from inside my Qt Creator. Valgrind is installed and runs from command line, but is not present in Qt Creator. Does someone else have this issue? QtCreator 2.01 Based on Qt 4.7.0 (64 bit) Ubuntu…
linello
  • 8,451
  • 18
  • 63
  • 109
1
vote
1 answer

Invalid read size in strcasestr

The following code: #include #include int main() { char *s = strdup("keep-alive"); if(strcasestr(s, "close")) { } free(s); return 0; } gives the following error in Valgrind: ==13183== Invalid read of size…
nevelis
  • 736
  • 6
  • 17
1
vote
3 answers

Need help tracking down an illegal write. valgrind not noticing it

ive got a C program that gets caught in a for loop that it shouldn't, running it with valgrind --tool=memcheck --leak-check=yes a.out doesnt return anything even up until the program gets caught. is there a way to change the settings of valgrind to…
swicano
  • 85
  • 1
  • 7
1
vote
3 answers

Why does setting a pointer to NULL give a error/warning in Valgrind?

I have a structure which contains some elements, i free the memory of this structure in a loop, roughly like: for (i = 0; i < teller; i++) { free((glycan+i)->desc); } free(glycan) I assume that the pointers are still pointing to the empty memory…
Bas Jansen
  • 3,273
  • 5
  • 30
  • 66
1
vote
1 answer

Why does this explicit destructor cause memory corruption in a shared ptr?

What is wrong with this code and how can I fix it? #include #include #include struct CTest { CTest() { std::cout << "ctor CTest" <
1
vote
1 answer

Different behaviour under valgrind vs normal execution?

I have a program witch is a xmpp client that connect to a server. I use gloox library to do that. When I run the program, it runs ok and connects to the server. But when I run it under valgrind, the program never sends
ruddy
  • 135
  • 4
  • 12
1
vote
5 answers

malloc char* inside a function, valgrind reports memory leak

I am pretty new to C, and am doing toy programs to learn it. The following code compiles, outputs correctly, but Valgrind reports a memory leak: #include #include #include #include "graph.h" void add_vertex(vertex…
Gal
  • 73
  • 1
  • 2
  • 6
1
vote
4 answers

Rewriting += Operator C++

UPDATE: Allocated memory for str1's new data. Still memory error. I'm trying to rewrite the += method for a string class I created. Class mystring{ public: friend void operator+=(mystring& str1, const mystring& str2){ mystring temp; …
KWJ2104
  • 1,959
  • 6
  • 38
  • 53
1
vote
2 answers

Would "still reachable" VALGRIND memory leaks (Linux) relate to PRSTAT memory growth on SOLARIS?

I am using Valgrind to check for leaks in a C application I have written. I am using 3rd party libraries...but am not 100% sure if the problem really lies in them only. If I run 10 message through my code I get the following on Linux: ==12460== LEAK…
Lynton Grice
  • 1,435
  • 3
  • 29
  • 45
1
vote
2 answers

Memory Leak in C with fopen

I have a simple piece of a program thats currently producing some memory leaks according to valgrind and I'm not sure why: char *filename = strrchr(argv[3], "/") + 1; file = fopen(fileName, "w"); So as far as I know, I give the program an argv[3]…
KWJ2104
  • 1,959
  • 6
  • 38
  • 53