2017-12-20 35 views
-3

오랜 시간 동안 실행되는 바이너리 프로그램에서 힙 증가 문제를 디버깅하려면 massif를 사용하고 있습니다. valgrind memcheck가 "익명 세그먼트에서"메시지를 보냅니다.

valgrind: m_mallocfree.c:280 (mk_plain_bszB): Assertion 'bszB != 0' failed. 
valgrind: This is probably caused by your program erroneously writing past the 
end of a heap block and corrupting heap metadata. If you fix any 
invalid writes reported by Memcheck, this assertion failure will 
probably go away. Please try that before reporting this as a bug. 
host stacktrace: 
==21766== at 0x58007769: show_sched_status_wrk (in /usr/lib64/valgrind/massif-amd64-linux) 
==21766== by 0x58007A44: report_and_quit (in /usr/lib64/valgrind/massif-amd64-linux) 
==21766== by 0x58007C77: vgPlain_assert_fail (in /usr/lib64/valgrind/massif-amd64-linux) 
==21766== by 0x58013D01: vgPlain_arena_free (in /usr/lib64/valgrind/massif-amd64-linux) 
==21766== by 0x5805CAE2: do_client_request (in /usr/lib64/valgrind/massif-amd64-linux) 
==21766== by 0x5805DCFE: vgPlain_scheduler (in /usr/lib64/valgrind/massif-amd64-linux) 
==21766== by 0x58011560: final_tidyup (in /usr/lib64/valgrind/massif-amd64-linux) 
==21766== by 0x5801191B: shutdown_actions_NORETURN (in /usr/lib64/valgrind/massif-amd64-linux) 
==21766== by 0x5808F42C: run_a_thread_NORETURN (in /usr/lib64/valgrind/massif-amd64-linux) 

sched status: 
    running_tid=1 

Thread 1: status = VgTs_Runnable (lwpid 21766) 
==21766== at 0x4A06F16: free (vg_replace_malloc.c:529) 
==21766== by 0x3CD630C24A: free_mem (in /lib64/libc-2.5.so) 
==21766== by 0x3CD630BE41: __libc_freeres (in /lib64/libc-2.5.so) 
==21766== by 0x480368A: _vgnU_freeres (vg_preloaded.c:77) 
==21766== by 0x3CD6233224: exit (exit.c:90) 
==21766== by 0x3CD621D9FA: (below main) (libc-start.c:262) 

그래서 내가 Valgrind의 --tool = memcheck -v tryed, 그리고 그것을보고 :하지만보고 내가 주 아래에 뭔가 오류에 대한 아이디어를 가지고하지

==21789== HEAP SUMMARY: 
==21789==  in use at exit: 0 bytes in 0 blocks 
==21789== total heap usage: 7,015 allocs, 7,016 frees, 805,222 bytes allocated 
==21789== 
==21789== All heap blocks were freed -- no leaks are possible 
==21789== 
==21789== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 6 from 4) 
==21789== 
==21789== 1 errors in context 1 of 1: 
==21789== Invalid free()/delete/delete[]/realloc() 
==21789== at 0x4A08B56: free (vg_replace_malloc.c:529) 
==21789== by 0x3CD630C24A: free_mem (in /lib64/libc-2.5.so) 
==21789== by 0x3CD630BE41: __libc_freeres (in /lib64/libc-2.5.so) 
==21789== by 0x480368A: _vgnU_freeres (vg_preloaded.c:77) 
==21789== by 0x3CD6233224: exit (exit.c:90) 
==21789== by 0x3CD621D9FA: (below main) (libc-start.c:262) 
==21789== Address 0x6374c98 is in a rw- anonymous segment 
==21789== 
--21789-- 
--21789-- used_suppression:  6 dl-hack3 /usr/lib64/valgrind/default.supp:1239 
==21789== 
==21789== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 6 from 4) 

.

+0

Valgrind Memcheck이 너무 나쁘다고해서 흥미로운 점을 지적하지 못했습니다. 위의 Memcheck는 작성한 코드를 호출합니까? 아니면 상용구 라이브러리 코드입니까? 아마도'/ usr/lib64/valgrind/default.supp'를 피하면 더 유용한 정보를 보여줄 것입니다. dtor 및 fini 함수에서 이상한 일이 발생합니다. 일부 프로그래머는 프로그램 종료에 매우 지저분하다고 느낍니다. 그들이 당신의 기능인 것처럼 정리 루틴이 있습니까? – jww

답변

0

malloc/free/.. (예 : memcheck 및 massif)를 대체하는 도구의 경우 valgrind는 기본적으로 실행됩니다. 예를 들어 glibc는 할당 된 메모리를 해제하는 함수를 제공합니다. C++ 런타임 또는 일부 glibc/동적 로더 데이터 구조. 이렇게하면 'memory leak free'보고서가 허용됩니다. 그러나 glibc 클리너가 valgrind가 가로 챈 적이없는 메모리 (아마도 너무 일찍 할당 되었는가? 이것은 명확하지 않음)에 의해 할당 된 일부 메모리를 해제하려고 시도하는 것처럼 보입니다.

두 가지가해야 할 :

  • 실행 --run-libc의-freeres와 함께 = 더 --run-CXX-freeres = 어떤 문제를 무시할 수 없습니다. ...
  • , 는 GCC 버전의 glibc 버전, 유통, Valgrind의 버전과 세부 사항을 필요로하는 모든 TNE을 제공
  • 파일 Valgrind의 버그질라에 위 대한 버그 (당신은 여전히 ​​할당 된 일부 메모리에 대해 불평 memcheck 볼 수 있습니다)