Valgrind does not show which line the error occurred

Asked

Viewed 49 times

1

I’m trying to use Valgrind for Linux in order to check for memory loss, however the error shown in the terminal does not show on which specific line it is.

==4873== Address 0x4a4e047 is 0 bytes after a block of size 7 alloc’d

==4873== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/Valgrind/vgpreload_memcheck-amd64-linux.so)

==4873== by 0x109221: getName (in /home/Rodrigo/Documents/Vscodetest/a. out)

==4873== by 0x1091D5: main (in /home/Rodrigo/Documents/Vscodetest/a. out)

1 answer

2


To make the valgrind display the lines, you can first compile the program using the GCC with the flag -g which indicates for the compilation to be performed by providing debug information:

gcc -g meu_programa.c -o meu_programa

When you run Valgrind, enter the flag --leak-check with the value full:

valgrind --leak-check=full ./meu_programa

Valgrind should display more details about the memory leak identified. As an example, for a program where I have not released the memory of a char* that had been allocated earlier, the message below was displayed on my terminal:

==387== 20 bytes in 1 blocks are definitely lost in loss record 1 of 1
==387==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==387==    by 0x1091CD: main (practice.c:8)

I hope I’ve helped in some way.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.