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

Valgrind memcheck invalid read of size 1

This example can be compiled and works as expected. 1 #include 2 #include 3 #include 4 5 char * getstr() { 6 return strdup("Hello"); 7 } 8 9 void *memcpy2(void *dest, const void *src, size_t len) 10 { 11 …
aicastell
  • 2,182
  • 2
  • 21
  • 33
1
vote
0 answers

Cuda problems using shared buffer for simulated memory allocation

I am converting a program from a regular c program to a cuda program and wanted to implement an easy wrapper for malloc that just uses a large pool. I have 5000 threads. My block size is 1024. Here is the buffer structure I am using to keep track…
Brian Crafton
  • 438
  • 2
  • 6
  • 15
1
vote
2 answers

What do the number of contexts in valgrind leak summary refer to?

I was profiling a c++ application using valgrind. In the leak summary, the number of errors is different from the number of contexts. What do contexts mean? `ERROR SUMMARY: 44911 errors from 1070 contexts (suppressed: 0 from 0)` Why are the number…
hAcKnRoCk
  • 1,118
  • 3
  • 16
  • 30
1
vote
1 answer

How can I avoid valgrind report mem lost when making memory pointer arithmetic?

I'm using valgrind's memcheck on my soft;But I have problems in this: for some reason we will transform the malloced pointer before store,and transform back when use.Just like this: char* ptr = (char*)malloc(1); ptr = ptr + 1; ...... origin_ptr =…
wchunyu
  • 11
  • 3
1
vote
1 answer

Why does an object allocation local to a Python subprocess increase heap size for main?

TL;DR According to Valgrind's memcheck tool, if I allocate a large local variable in a function and launch that function using multiprocessing.Pool().apply_async(), the heap size for both the subprocess and the main process increases. Why does…
1
vote
1 answer

C - Valgrind detects an error in my reverse-string function

I wrote a small program that seems to work fine, but valgrind give me a weird error when I run memcheck. I need help in interpreting the error code :) #include #include int get_length(char* str){ int i=0; char c =…
Atlas80b
  • 119
  • 1
  • 2
  • 8
1
vote
1 answer

Valgrind won't detect obvious errors

I am in the process of learning C from Zed Shaw's excellent Learn C the Hard Way. I am running Debian Sid with kernel version 3.9.0-vanillaice amd64 (I compiled it) with glibc 2.17 (installed from Debian's repo's). I am on Exercise 4 in the…
axuak
  • 13
  • 4
1
vote
1 answer

Is it feasible to record a program state in Valgrind/DrMemory and then restore that?

I have a program that loads a big chunk of data at startup. That takes up a rather long time and therefore creates an overhead when running Valgrind (memcheck)/DrMemory. So when invoking the program several times with different arguments, it takes…
0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
1
vote
1 answer

What causes mkstemp to fail when running many simultaneous valgrind processes?

I'm doing testing of some software with valgrind. Ideally, I would like to have 20 or more instances of valgrind open at once. However, if I run more than 16 instances in parallel, I start getting messages like: ==30533== VG_(mkstemp): failed to…
John Doucette
  • 4,370
  • 5
  • 37
  • 61
1
vote
1 answer

Qt memory error - valgrind trace analysis help needed

Do you have any theory how to debug this potentially problematic memory access pattern? I have hunch it might be related to a certain heisen-bug I'm experiencing, but I can't seem to pinpoint it. it's a snippet of a run of debug build, under…
qdot
  • 6,195
  • 5
  • 44
  • 95
1
vote
1 answer

can't make sense of valgrind output

Can't make sense of .eh_frame section mapping ==4780== Use of uninitialised value of size 4 ==4780== at 0x4011D18: ??? (in /lib/ld-2.3.2.so) ==4780== by 0x401628F: ??? ==4780== by 0x4006227: ??? (in /lib/ld-2.3.2.so) …
0
votes
1 answer

more intuitive backtrace of valgrind memcheck in c++ program?

I obtained the following output after running my c++ program in debug mode with valgrind --tool=memcheck --leak-check=full ./my_program ==1904766== ==1904766== HEAP SUMMARY: ==1904766== in use at exit: 209,434 bytes in 1,309 blocks ==1904766==…
Simon
  • 325
  • 1
  • 6
0
votes
1 answer

Valgrind program is crashing Bad permissions for mapped region at address

I am trying to run my program to check memory leaks in my program but whenever I start my program I am getting ==3476== Process terminating with default action of signal 11 (SIGSEGV): dumping core ==3476== Bad permissions for mapped region at…
Vivek Goel
  • 22,942
  • 29
  • 114
  • 186
0
votes
1 answer

Valgrind(memcheck) not showing all contexts

My last context/error I see in my valgrind output file is... ==3030== 1075 errors in context 61 of 540: ==3030== Syscall param ioctl(SIOCETHTOOL,ir) points to uninitialised byte(s) ==3030== at 0x7525248: ioctl (syscall-template.S:84) ==3030== …
JoeManiaci
  • 435
  • 3
  • 15
0
votes
1 answer

Connection to valgrind embedded gdb server is failing with an error "Connection reset by peer"

I trying to follow the instruction on connecting to valgrind using gdb. Valgrind memcheck is starts properly and asks to connect using following gdb command: target remote | vgdb --pid=53181 but when I run this command, I get an error Remote…
George Vinokhodov
  • 327
  • 1
  • 4
  • 10