Выбрать главу

==30882== by 0x8048460: broken (broken.с:22)

==30882== by 0x804851F: main (broken.с:47)

==30882== Address 0x650F064 is 3 bytes after a block of size 5 alloc'd

==30882== at 0xC0C28B: malloc (vg_replace_malloc.с:153)

==30882== by 0x8048437: broken (broken.с:20)

==30882== by 0x804851F: main (broken.с:47)

==30882== by 0x802BAE: __libc_start_main (in /lib/libc-2.3.2.so)

==30882==

==30882== Invalid read of size 1

==30882== at 0x857A21: _IO_file_xsputn@@GLIBC_2.1 (in /lib/libc-2.3.2.so)

==30882== by 0x835309: _IO_vfprintf_internal (in /lib/libc-2.3.2.so)

==30882== by 0x83BC31: _IO_printf(in /lib/libc-2.3.2.so)

==30882== by 0x8048460: broken (broken.с:22)

==30882== Address 0x650F063 is 2 bytes after a block of size 5 alloc'd

==30882== at 0xC0C28B: malloc (vg_replace_malloc.с:153)

==30882== by 0x8048437: broken (broken.с:20)

==30882== by 0x804851F: main (broken.c:47)

==30882== by 0x802BAE: __libc_start_main (in /lib/libc-2.3.2.so)

==30882==

==30882== Invalid read of size 1

==30882== at 0x857910: _IO_file_xsputn@@GLIBC_2.1 (in /lib/libc-2.3.2.so)

==30882== by 0x835309: _IO_vfprintf_internal (in /lib/libc-2.3.2.so)

==30882== by 0x83BC31: _IO_printf (in /lib/libc-2.3.2.so)

==30882== by 0x8048460: broken (broken.с:22)

==30882== Address 0x650F061 is 0 bytes after a block of size 5'alloc'd

==30882== at 0xC0C28B: malloc (vg_replace_malloc.с:153)

==30882== by 0x8048437: broken (broken.с:20)

==30882== by 0x804851F: main (broken.с:47)

==30882== by 0x802BAE: __libc_start_main (in /lib/libc-2.3.2.so)

2: 12345678

==30882==

==30882== Invalid write of size 1

==30882== at 0x8048468: broken (broken.с:25)

==30882== by 0x804851F: main (broken.с:47)

==30882== by 0x802BAE: __libc_start_main (in /lib/libc-2.3.2.so)

==30882== by 0x8048354: (within /usr/src/d/lad2/code/broken)

==30882== Address 0x650F05B is 1 bytes before a block of size 5 alloc'd

==30882== at 0xC0C28B: malloc (vg_replace_malloc.c:153)

==30882== by 0x8048437: broken (broken.с:20)

==30882== by 0x804851F: main (broken.с:47)

==30882== by 0x802BAE: __libc_start_main (in /lib/libc-2.3.2.so)

==30882==

==30882== Invalid read of size 4

==30882== at 0x863D50: __GI_strlen (in /lib/libc-2.3.2.so)

==30882== by 0x83BC31: _IO_printf (in /lib/libc-2.3.2.so)

==30882== by 0x804847A: broken (broken.c:2 6)

==30882== by 0x804851F: main (broken.c:47)

==30882== Address 0x650F064 is 3 bytes after a block of size 5 alloc'd

==30882== at 0xC0C28B: malloc (vg_replace_malloc.c:153)

==30882== by 0x8048437: broken (broken.с:20)

==30882== by 0x804851F: main (broken.c:47)

==30882== by 0x802BAE: __libc_start_main (in /lib/libc-2.3.2.so)

==30882==

==30882== Invalid read of size 1

==30882== at 0x857A21: _IO_file_xsputn@@GLIBC_2.1 (in /lib/libc-2.3.2.so)

==30882== by 0x835309: _IO_vfprintf_internal (in /lib/libc-2.3.2.so)

==30882== by 0x83BC31: _IO_printf (in /lib/libc-2.3.2.so)

==30882== by 0x804847A: broken (broken.c:2 6)

==30882== Address 0x650F063 is 2 bytes after a block of size 5 alloc'd

==30882== at 0xC0C28B: malloc (vg_replace_malloc.c:153)

==30882== by 0x8048437: broken (broken.с:20)

==30882== by 0x804851F: main (broken.с:47)

==30882== by 0x802BAE: __libc_start_main (in /lib/libc-2.3.2.so)

==30882==

==30882== Invalid read of size 1

==30882== at 0x857910: _IO_file_xsputn@@GLIBC_2.1 (in /lib/libc-2.3.2.so)

==30882== by 0x835309: _IO_vfprintf_internal (in /lib/libc-2.3.2.so)

==30882== by 0x83BC31: _IO_printf (in /lib/libc-2.3.2.so) ==30882== by 0x804847A: broken (broken.c:2 6)

==30882== Address 0x650F061 is 0 bytes after a block of size 5 alloc'd

==30882== at 0xC0C28B: malloc (vg_replace_malloc.с:153)

==30882== by 0x8048437: broken (broken.с:20)

==30882== by 0x804851F: main (broken.с:47)

==30882== by 0x802BAE: __libc_start_main (in /lib/libc-2.3.2.so)

3: 12345678

4: 12345

==30882==

==30882== Invalid write of size 1

==30882== at 0x80484A6; broken (broken.c:3 2)

==30882== by 0x804851F: main (broken.с:47)

==30882== by 0x802BAE: __libc_start_main (in /lib/libc-2.3.2.so)

==30882== by 0x8048354: (within /usr/src/d/lad2/code/broken)

==30882== Address 0xBFF2D0FF is just below %esp. Possibly a bug in GCC/G++

==30882== v 2.96 or 3.0.X. To suppress, use: --workaround-gcc 296-bugs = yes

5: 12345

6: 12345

7: 12345

==30882==

==30882== ERROR SUMMARY: 22 ERRORS from 12 contexts (suppressed: 0 from 0)

==30882== malloc/free: in use at exit: 5 bytes in 1 blocks.

==30882== malloc/free: 2 allocs, 1 frees, 10 bytes allocated.

==30882== For a detailed leak analysis, rerun with: --leak-check=yes

==30882== For counts of detected ERRORS, rerun with: -v

==30882== ИТОГИ ПО ОШИБКАМ: 22 ошибки в 12 контекстах (подавлено: 0 из 0)

==30882== malloc/free: используются после завершения: 5 байт в 1 блоке.

==30882== malloc/free: 2 распределения, 1 освобождение, 10 байт распределено.

==30882== Для детального анализа утечек памяти запустите с: --leak-check=yes

==30882== Для подсчета обнаруженных ошибок запустите с: -v

Обратите внимание, что Valgrind нашел все, кроме глобального переполнения и недогрузки, и указал на ошибки более точно, нежели любое другое ранее описанное средство.

Имеется опция, позволяющая включить агрессивную проверку утечек памяти, при которой для каждого распределения находятся все доступные указатели, хранящие ссылку на эту память. Это более точный способ, поскольку часто в программе память распределяют, но в конце не освобождают, так как память в любом случае будет возвращена операционной системе после того, как программа завершится.

$ valgrind --leak-check=yes ./broken

...

==2292== searching for pointers to 1 not-freed blocks.

==2292== checked 5318724 bytes.

==2292== поиск указателей на 1 неосвобожденный блок.