LINUX.ORG.RU

как локализовать memory leak через valgrind?


0

0

к примеру вот мое:
valgrind --tool=memcheck ./editor2

==6181== Memcheck, a memory error detector for x86-linux.
==6181== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
==6181== Using valgrind-2.4.0, a program supervision framework for x86-linux.
==6181== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
==6181== For more details, rerun with: -v
==6181== 
==6181== Conditional jump or move depends on uninitialised value(s)
==6181==    at 0x6ECBE0: strstr (in /lib/libc-2.3.5.so)
==6181==    by 0x7F36E7: __pthread_initialize_minimal (in /lib/libpthread-2.3.5.so)
==6181==    by 0x7F3297: (within /lib/libpthread-2.3.5.so)
==6181==    by 0x7F2E7F: (within /lib/libpthread-2.3.5.so)
==6181==    by 0x1B8F1DCA: call_init (in /lib/ld-2.3.5.so)
==6181==    by 0x1B8F1EEC: _dl_init (in /lib/ld-2.3.5.so)
==6181==    by 0x1B8E47CE: (within /lib/ld-2.3.5.so)
==6181== 
==6181== Conditional jump or move depends on uninitialised value(s)
==6181==    at 0x6ECBE4: strstr (in /lib/libc-2.3.5.so)
==6181==    by 0x7F36E7: __pthread_initialize_minimal (in /lib/libpthread-2.3.5.so)
==6181==    by 0x7F3297: (within /lib/libpthread-2.3.5.so)
==6181==    by 0x7F2E7F: (within /lib/libpthread-2.3.5.so)
==6181==    by 0x1B8F1DCA: call_init (in /lib/ld-2.3.5.so)
==6181==    by 0x1B8F1EEC: _dl_init (in /lib/ld-2.3.5.so)
==6181==    by 0x1B8E47CE: (within /lib/ld-2.3.5.so)
==6181== 
==6181== Conditional jump or move depends on uninitialised value(s)
==6181==    at 0x804B248: (within /opt/prog/editor2)
==6181== 
==6181== Conditional jump or move depends on uninitialised value(s)
==6181==    at 0x804B253: (within /opt/prog/editor2)
==6181== 
==6181== ERROR SUMMARY: 104 errors from 4 contexts (suppressed: 394 from 2)
==6181== malloc/free: in use at exit: 1889729 bytes in 497 blocks.
==6181== malloc/free: 89898 allocs, 89401 frees, 31731824 bytes allocated.
==6181== For counts of detected errors, rerun with: -v
==6181== searching for pointers to 497 not-freed blocks.
==6181== checked 244612 bytes.
==6181== 
==6181== LEAK SUMMARY:
==6181==    definitely lost: 1866072 bytes in 96 blocks.
==6181==      possibly lost: 0 bytes in 0 blocks.
==6181==    still reachable: 23657 bytes in 401 blocks.
==6181==         suppressed: 0 bytes in 0 blocks.
==6181== Use --leak-check=full to see details of leaked memory.


с ключем --leak-check=full еще больше информации:
==6185== 
==6185== Conditional jump or move depends on uninitialised value(s)
==6185==    at 0x804B248: (within /opt/prog/editor2)
==6185== 
==6185== Conditional jump or move depends on uninitialised value(s)
==6185==    at 0x804B253: (within /opt/prog/editor2)
==6185== 
==6185== ERROR SUMMARY: 80 errors from 4 contexts (suppressed: 333 from 2)
==6185== malloc/free: in use at exit: 1889729 bytes in 497 blocks.
==6185== malloc/free: 89908 allocs, 89411 frees, 31732864 bytes allocated.
==6185== For counts of detected errors, rerun with: -v
==6185== searching for pointers to 497 not-freed blocks.
==6185== checked 244612 bytes.
==6185== 
==6185== 
==6185== 421584 (156 direct, 421428 indirect) bytes in 13 blocks are definitely lost in loss record 41 of 46
==6185==    at 0x1B909222: malloc (vg_replace_malloc.c:130)
==6185==    by 0x80496E7: (within /opt/h2/editor2)
==6185== 
==6185== 
==6185== 1444488 (36 direct, 1444452 indirect) bytes in 3 blocks are definitely lost in loss record 45 of 46
==6185==    at 0x1B909222: malloc (vg_replace_malloc.c:130)
==6185==    by 0x8049649: (within /opt/h2/editor2)
==6185==    by 0x492E524E: ???
==6185== 
==6185== LEAK SUMMARY:
==6185==    definitely lost: 192 bytes in 16 blocks.
==6185==    indirectly lost: 1865880 bytes in 80 blocks.
==6185==      possibly lost: 0 bytes in 0 blocks.
==6185==    still reachable: 23657 bytes in 401 blocks.
==6185==         suppressed: 0 bytes in 0 blocks.
==6185== Reachable blocks (those to which a pointer was found) are not shown.

то есть правильно ли я понял что 100% потеряно 192 байта?
а indirectly lost это чьё?
★★★★★

В первом листинге (без --leak-check=full) у тебя показывались места, где переменная неинициализирована. Т.е., к примеру, ты определил переменную и тут же её передаёшь ф-ции и valgrind ругается, т.к. если ты без проверки в этой ф-ции заюзаешь это значение то программа потом может просто упасть.

Во втором случае уже видны утечки. Да, у тебя утекает 192 байта :) Только чтобы лучше понять где утекает, рекомендуют компилировать программу с опциями -g -O0. Тогда вместо адресов в памяти будет показываться файл, номер строки и имя ф-ции.

P.S. См. также: http://www.linux.org.ru/profile/php-coder/view-message.jsp?msgid=1223731

php-coder ★★★★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.