Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

valgrind - address is 8 bytes before a block of size 16 alloc'd

Tags:

c

valgrind

I'm having a problem with "digesting" valgrind output. Here's a snippet:

==15145== Invalid write of size 8
==15145==    at 0x40168E: split_node_at_letter (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x4018E7: pass_word_further (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x401A35: insert_word (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x401BD5: main (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==  Address 0x52237d8 is 8 bytes before a block of size 16 alloc'd
==15145==    at 0x4C29BCF: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==15145==    by 0x401063: add_to_trie_word_list (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x40173B: pass_word_further (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x40183D: pass_word_further (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x401906: pass_word_further (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x401A35: insert_word (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x401BD5: main (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)

What does it mean that the address is "8 bytes before a block of size 16 alloc'd"?

like image 890
qiubit Avatar asked Apr 21 '15 15:04

qiubit


1 Answers

It means Valgrind detected one block of memory you alloc'd (through malloc() or similar) for your program, and that you try to access the address which is 8 bytes before that.

In short, this is an Array Out of Bounds error, with you trying to access data before the actual array data

An incorrect write means you assign a value to something in this data-segment. For example doing word.length = 4

Here is the breakdown of valgrind's ouput:

==15145== Invalid write of size 8
             //This is the function doing the incorrect accessing
==15145==    at 0x40168E: split_node_at_letter (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
           [... stack trace ...]

                //This is the address you are trying to access
==15145==  Address 0x52237d8 is 8 bytes before a block of size 16 alloc'd
==15145==    at 0x4C29BCF: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)

             //This is the function that alloc'd the 'block of size 16' (calling malloc as shown in the above line)
==15145==    by 0x401063: add_to_trie_word_list (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)

           [... stack trace ...]
like image 196
Eregrith Avatar answered Oct 28 '22 04:10

Eregrith