Questions tagged [memcheck]

Memcheck is the dynamic memory error detector tool present in Valgrind framework. It mainly helps detecting dynamic memory allocation-deallocation related error. This tool can be used for C / C++ codes.

Memcheck is the dynamic memory error checker tool present in the framework. It can detect dynamic memory usage related errors in and programs. Mainly, it shows the erroneous cases for the following scenarios

  1. Accessing memory you shouldn't, e.g. overrunning and underrunning heap blocks, overrunning the top of the stack, and accessing memory after it has been freed.
  2. Using undefined values, i.e. values that have not been initialised, or that have been derived from other undefined values.
  3. Incorrect freeing of heap memory, such as double-freeing heap blocks, or mismatched use of malloc/new/new[] versus free/delete/delete[].
  4. Overlapping src and dst pointers in memcpy and related functions.
  5. Memory leaks.

While using valgrind freamework for testing a program, memcheck is the default tool to be used for checking. When memcheck finds any error in the program, it prints out the error type and possible location in the code, along with some other process related information which helps to find out the erroneous piece of code and fix it.

Any dynamic memory debugging done with memechek tool [or default valgrind tool] are to be marked with this tag.

96 questions
25
votes
1 answer

Recommended way to track down array out-of-bound access/write in C program

Consider writing implementation for some not-so-obvious algorithm in C. For example let it be recursive quicksort, that I have found in K. N. King's "C Programming: A Modern Approach, 2nd Edition" book, that it's available from here. The most…
Grzegorz Szpetkowski
  • 36,988
  • 6
  • 90
  • 137
11
votes
1 answer

How to pass arguments to memcheck with ctest?

I want to use ctest from the command line to run my tests with memcheck and pass in arguments for the memcheck command. I can run ctest -R my_test to run my test, and I can even run ctest -R my_test -T memcheck to run it through memcheck. But I…
dcmm88
  • 1,445
  • 1
  • 12
  • 30
8
votes
3 answers

What does possible lost means in valgrind

I have a lot of possible lost entry from valgrind. What does that mean ? As I am using sqlite and it is well tested. I don't think these are correct entry. What I am doing wrong ? 16 bytes in 1 blocks are possibly lost in loss record 30 of 844 …
Vivek Goel
  • 22,942
  • 29
  • 114
  • 186
7
votes
1 answer

cuda-memcheck, how to get from address to source code?

I successfully used cuda-memcheck to get errors about wrong memory accesses. Compiling the cuda code with -g -G gave nice source locations like this: ========= Error: process didn't terminate successfully ========= Invalid __global__ read of size…
Jan Rüegg
  • 9,587
  • 8
  • 63
  • 105
7
votes
0 answers

Valgrind complains bytes are being lost at std::string constructor

I am new to valgrind, so this could be missintepreting the output. Valgrind seems to think bytes are being lost in the following lines: if ( mysqlpp::StoreQueryResult result = query.store() ){ for ( size_t i = 0; i < result.num_rows(); ++i ){ …
Ælex
  • 14,432
  • 20
  • 88
  • 129
7
votes
1 answer

How to see heap and stack usage of a function in c using valgrind?

I am working on a embedded system. We have limited stack and heap in our embedded system typically 64k (ram). I am trying to use polar-ssl library calls. Is there any tools which tells how much stack and heap memory is used by a C function? Is…
yuvaeasy
  • 823
  • 2
  • 10
  • 18
6
votes
1 answer

"Serious error when reading debug info" - suppress? ignore? fix?

I'm using valgrind to try and locate the cause of a violating memory access in a C-cum-C++ program. Even with this access averted (i.e. when everything runs fine), valgrind tells me: ==11436== Memcheck, a memory error detector ==11436== Copyright…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
6
votes
3 answers

How do I merge Valgrind memcheck reports from multiple runs of the same process?

I've got an set of acceptance tests that run nightly. I'd like to use valgrind to check for memory leaks in my code automatically as an additional safe-guard to manually checking for leaks. Updating my scripts to run my processes under valgrind is…
Glen
  • 21,816
  • 3
  • 61
  • 76
6
votes
2 answers

Trace for function name from the output of cuda-memcheck

I'm running to cuda-memcheck to debug my code and the output is as follows ========= Program hit cudaErrorCudartUnloading (error 29) due to "driver shutting down" on CUDA API call to cudaFree. ========= Saved host backtrace up to driver entry…
Hieu Pham
  • 97
  • 1
  • 8
6
votes
2 answers

How can I prevent Valgrind from starting embedded gdbservers for every new thread?

I'm running valgrind memcheck on a program that spawns thousands of other threads. The other threads do not generate errors, and I don't care what happens to them. However, Valgrind insists on opening a named pipe in /tmp every time a new thread…
John Doucette
  • 4,370
  • 5
  • 37
  • 61
6
votes
3 answers

dump valgrind data

I am using valgrind on a program which runs an infinite loop. As memcheck displays the memory leaks after the end of the program, but as my program has infinite loop it will never end. So is there any way i can forcefully dump the data from…
user414209
  • 361
  • 1
  • 5
  • 15
5
votes
0 answers

Is there any way to name mempools in valgrind memcheck?

PostgreSQL makes heavy use of memory pools and, when Valgrind is enabled, supplies information about them to Valgrind using VALGRIND_CREATE_MEMPOOL etc. Combined with incremental leak checking using client-requests like VALGRIND_DO_LEAK_CHECK and…
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
5
votes
1 answer

Is it possible to run valgrind on the iOS simulator and device?

I need to debug heap overflows in a very large project. After playing with valgrind a bit, it seems like the perfect tool for detecting heap block overruns in C, so I'd like to run our iOS app with it. I've built and installed valgrind from trunk…
Joey Carson
  • 2,973
  • 7
  • 36
  • 60
5
votes
3 answers

Analyze valgrind output: "invalid free()"

I have this strange error found by valgrind on a (stupid) authentication module which makes some on heap allocations. ==8009== Invalid free() / delete / delete[] / realloc() ==8009== at 0x4C2A739: free (in…
Fabio Carello
  • 1,062
  • 3
  • 12
  • 30
4
votes
6 answers

Should I worry about "Conditional jump or move depends on uninitialised value(s)"?

If you've used Memcheck (from Valgrind) you'll probably be familiar with this message... Conditional jump or move depends on uninitialized value(s) I've read about this and it simply occurs when you use an uninitialized value. MyClass…
Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
1
2 3 4 5 6 7