Memory Leak에 대한 질문 입니다..
회사에서 개발 중인 Software를 중간 점검하고자,
Valgrind를 돌려봤습니다.
그랬더니..
==30991== LEAK SUMMARY:
==30991== definitely lost: 0 bytes in 0 blocks.
==30991== possibly lost: 0 bytes in 0 blocks.
==30991== still reachable: 90,891 bytes in 1,767 blocks.
==30991== suppressed: 0 bytes in 0 blocks.
라는 결과가 나오네요..
"still reachable"이 무슨 뜻인가 해서 Valgrind manual을 찾아보니,,
• Still reachable: A pointer to the start of the block is found. This usually indicates programming sloppiness. Since the block is still pointed at, the programmer could, at least in principle, free it before program exit. Because these are very common and arguably not a problem, Memcheck won’t report such blocks unless
--show-reachable=yes is specified.
이라고 하네요. programming sloppiness라고 하면 깔끔하지 못한 programming정도로 보면되나요?
이런 경우에는 얼마나 위험한건지,,감이 잘 안잡히네요 ..
이런 경험으로 memory leak에 대한 debugging을 해보신 분이 계실 것 같은데,,
조언을 좀 부탁드려도 될까요?
미리 감사드립니다. ^^
valgrind 에 추가 질문이 생겨서 글을 올립니다..
위에 올렸던 질문 중에서요..
==30991== LEAK SUMMARY:
==30991== definitely lost: 0 bytes in 0 blocks.
==30991== possibly lost: 0 bytes in 0 blocks.
==30991== still reachable: 90,891 bytes in 1,767 blocks.
==30991== suppressed: 0 bytes in 0 blocks.
"30991"은 어떤 의미일까요?
Valgrind manual에는 process ID인데 중요하지 않다..
이렇게 나와 있네요.
실제로 이런 ID를 가진 process가 있나 ps -eLf를 해보면 없는 것 같습니다.
그리고 또 한가지 질문을 드리고 싶은 것은요 ..
valgrind "executable file name" 이라는 방법 말고,
/etc/init.d 아래에 있는 script를 이름으로 주면 어떻게 동작하는 건지도
질문 드리고 싶네요..
시험 삼아서 valgrind /etc/sshd 이렇게 해봤는데...
결과는
==9616== LEAK SUMMARY:
==9616== definitely lost: 1,073 bytes in 20 blocks.
==9616== possibly lost: 0 bytes in 0 blocks.
==9616== still reachable: 879 bytes in 24 blocks.
==9616== suppressed: 0 bytes in 0 blocks.
==9616== Rerun with --leak-check=full to see details of leaked memory.
이렇게 나옵니다..
그럼..sshd script에 문제가 있는 걸까요?
아니면 sshd script내에서 실행하는 어떤 executable에 문제가 있는 걸까요?
아니면 아예 이렇게 하면 안되는 걸까요?
조언 부탁 드립니다..
잘모르지만...
> ==30991==
PID 입니다.
> still reachable: 879 bytes in 24 blocks.
879 바이트 프리전이란 말씀이고요. 24blocks에 걸려있다란 뜻입니다.
Hello World.
...
오래돼서 잘 기억은 안나지만, valgrind를 쓸 때 --show-reachable=yes를 주시면 아마 얘들이 어디서 나온 건지 보여줄 겁니다.
일반적으로 still reachable의 크기가 프로그램을 오래 돌릴수록 계속 커지거나 하지 않으면 별로 신경쓰실 필요 없습니다.
30991은 해당 프로세스의 PID이고요, 해당 프로세스가 종료한 다음에 ps 해보면 당연히 없죠.
etc/sshd가 정확히 어떤 건지 모르겠는데 shell script라면 이를 실행하는 /bin/sh(혹은 다른 적절한 shell interpreter)에서 memory leak가 발생했다는 뜻입니다. /bin/sh를 디버깅할 것이 아니면 그냥 무시하시면 됩니다.
임의의 shell script나 실행파일이 실행하는 모든 child process까지 valgrind를 붙이고 싶으시면 --trace-children=yes를 주고 실행시켜 보세요.
좀 더 시험을 해보았습니다..
아래와 같이 Option을 주고 해보니까, memory 사용에 문제가 있는 걸로 보이네요.
Error message는 거의 비슷한 형태를 가지는 것 같은데요..
항상 첫번째 line에 나오는 vg_replace_malloc.c 는 무시하라고 Manual에 있는 것 같고요 ..
나머지를 어떻게 해석해야 하는지 잘 모르겠습니다..
일단 within /sbin/modprobe 라고 나와 있는 내용이 혹시 modprobe utility에 memory leak이
있나 싶어서 valgrind /sbin/modprobe 를 실행해 보니까, 특별히 modprobe자체에
memory leak이 있다고 보이지는 않네요..
그리고 below main이라는 line의 내용도 잘 이해가 안갑니다. 혹시 무슨 내용일까요?
이걸 보면서 막연하게 추측하는 것은 제 program내에 main 이라는 function이 있고, 또 그
main function에서 modprobe utility를 사용해서 module하나를 include하는 line이 있는데
그 module이 뭔가 잘못된걸까 하는생각도 들고요 ..
만일 그렇다면 왜 이렇게 많은 error가 보일까도 궁금하네요.
error가 하나만 보여야 하지 않을까 생각도 들었고요 ..
이해를 제대로 못해서,,고생중입니다. ^^
조언 부탁드립니다 ~
# valgrind --trace-children=yes --leak-check=full ./test_program
==17332== Memcheck, a memory error detector.
==17332== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==17332== Using LibVEX rev 1854, a library for dynamic binary translation.
==17332== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==17332== Using valgrind-3.3.1, a dynamic binary instrumentation framework.
==17332== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==17332== For more details, rerun with: -v
==17332==
==17333== Memcheck, a memory error detector.
==17333== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==17333== Using LibVEX rev 1854, a library for dynamic binary translation.
==17333== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==17333== Using valgrind-3.3.1, a dynamic binary instrumentation framework.
==17333== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==17333== For more details, rerun with: -v
==17333==
==17333== Memcheck, a memory error detector.
==17333== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==17333== Using LibVEX rev 1854, a library for dynamic binary translation.
==17333== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==17333== Using valgrind-3.3.1, a dynamic binary instrumentation framework.
==17333== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==17333== For more details, rerun with: -v
==17333==
==17333==
==17333== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 13 from 1)
==17333== malloc/free: in use at exit: 3,264 bytes in 188 blocks.
==17333== malloc/free: 768 allocs, 580 frees, 336,027 bytes allocated.
==17333== For counts of detected errors, rerun with: -v
==17333== searching for pointers to 188 not-freed blocks.
==17333== checked 46,520 bytes.
==17333==
==17333== 1 bytes in 1 blocks are definitely lost in loss record 1 of 12
==17333== at 0x402097E: calloc (vg_replace_malloc.c:397)
==17333== by 0x804B9E6: (within /sbin/modprobe)
==17333== by 0x804C774: (within /sbin/modprobe)
==17333== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17333==
==17333==
==17333== 22 bytes in 1 blocks are definitely lost in loss record 2 of 12
==17333== at 0x4021858: malloc (vg_replace_malloc.c:207)
==17333== by 0x804BF35: (within /sbin/modprobe)
==17333== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17333==
==17333==
==17333== 36 bytes in 1 blocks are definitely lost in loss record 3 of 12
==17333== at 0x4021858: malloc (vg_replace_malloc.c:207)
==17333== by 0x804BF96: (within /sbin/modprobe)
==17333== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17333==
==17333==
==17333== 38 bytes in 1 blocks are definitely lost in loss record 4 of 12
==17333== at 0x4021858: malloc (vg_replace_malloc.c:207)
==17333== by 0x804BFE9: (within /sbin/modprobe)
==17333== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17333==
==17333==
==17333== 706 (8 direct, 698 indirect) bytes in 1 blocks are definitely lost in
loss record 6 of 12
==17333== at 0x4021858: malloc (vg_replace_malloc.c:207)
==17333== by 0x804B572: (within /sbin/modprobe)
==17333== by 0x804B074: (within /sbin/modprobe)
==17333== by 0x804B803: (within /sbin/modprobe)
==17333== by 0x804C1BC: (within /sbin/modprobe)
==17333== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17333==
==17333==
==17333== 885 bytes in 39 blocks are definitely lost in loss record 8 of 12
==17333== at 0x402192E: realloc (vg_replace_malloc.c:429)
==17333== by 0x8049BAF: (within /sbin/modprobe)
==17333== by 0x804B0CC: (within /sbin/modprobe)
==17333== by 0x804B074: (within /sbin/modprobe)
==17333== by 0x804B803: (within /sbin/modprobe)
==17333== by 0x804C1BC: (within /sbin/modprobe)
==17333== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17333==
==17333==
==17333== 1,470 (12 direct, 1,458 indirect) bytes in 1 blocks are definitely los
t in loss record 9 of 12
==17333== at 0x4021858: malloc (vg_replace_malloc.c:207)
==17333== by 0x80499C1: (within /sbin/modprobe)
==17333== by 0x804B30F: (within /sbin/modprobe)
==17333== by 0x804B074: (within /sbin/modprobe)
==17333== by 0x804B803: (within /sbin/modprobe)
==17333== by 0x804C1BC: (within /sbin/modprobe)
==17333== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17333==
==17333==
==17333== 106 (59 direct, 47 indirect) bytes in 1 blocks are definitely lost in
loss record 11 of 12
==17333== at 0x4021858: malloc (vg_replace_malloc.c:207)
==17333== by 0x8049A7E: (within /sbin/modprobe)
==17333== by 0x804A185: (within /sbin/modprobe)
==17333== by 0x804C665: (within /sbin/modprobe)
==17333== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17333==
==17333== LEAK SUMMARY:
==17333== definitely lost: 1,061 bytes in 46 blocks.
==17333== indirectly lost: 2,203 bytes in 142 blocks.
==17333== possibly lost: 0 bytes in 0 blocks.
==17333== still reachable: 0 bytes in 0 blocks.
==17333== suppressed: 0 bytes in 0 blocks.
==17418== Memcheck, a memory error detector.
==17418== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==17418== Using LibVEX rev 1854, a library for dynamic binary translation.
==17418== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==17418== Using valgrind-3.3.1, a dynamic binary instrumentation framework.
==17418== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==17418== For more details, rerun with: -v
==17418==
==17418== Memcheck, a memory error detector.
==17418== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==17418== Using LibVEX rev 1854, a library for dynamic binary translation.
==17418== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==17418== Using valgrind-3.3.1, a dynamic binary instrumentation framework.
==17418== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==17418== For more details, rerun with: -v
==17418==
==17418==
==17418== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 13 from 1)
==17418== malloc/free: in use at exit: 3,536 bytes in 192 blocks.
==17418== malloc/free: 692 allocs, 500 frees, 288,886 bytes allocated.
==17418== For counts of detected errors, rerun with: -v
==17418== searching for pointers to 192 not-freed blocks.
==17418== checked 46,520 bytes.
==17418==
==17418== 1 bytes in 1 blocks are definitely lost in loss record 1 of 13
==17418== at 0x402097E: calloc (vg_replace_malloc.c:397)
==17418== by 0x804B9E6: (within /sbin/modprobe)
==17418== by 0x804C774: (within /sbin/modprobe)
==17418== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17418==
==17418==
==17418== 22 bytes in 1 blocks are definitely lost in loss record 2 of 13
==17418== at 0x4021858: malloc (vg_replace_malloc.c:207)
==17418== by 0x804BF35: (within /sbin/modprobe)
==17418== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17418==
==17418==
==17418== 36 bytes in 1 blocks are definitely lost in loss record 3 of 13
==17418== at 0x4021858: malloc (vg_replace_malloc.c:207)
==17418== by 0x804BF96: (within /sbin/modprobe)
==17418== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17418==
==17418==
==17418== 38 bytes in 1 blocks are definitely lost in loss record 4 of 13
==17418== at 0x4021858: malloc (vg_replace_malloc.c:207)
==17418== by 0x804BFE9: (within /sbin/modprobe)
==17418== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17418==
==17418==
==17418== 706 (8 direct, 698 indirect) bytes in 1 blocks are definitely lost in
loss record 6 of 13
==17418== at 0x4021858: malloc (vg_replace_malloc.c:207)
==17418== by 0x804B572: (within /sbin/modprobe)
==17418== by 0x804B074: (within /sbin/modprobe)
==17418== by 0x804B803: (within /sbin/modprobe)
==17418== by 0x804C1BC: (within /sbin/modprobe)
==17418== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17418==
==17418==
==17418== 885 bytes in 39 blocks are definitely lost in loss record 8 of 13
==17418== at 0x402192E: realloc (vg_replace_malloc.c:429)
==17418== by 0x8049BAF: (within /sbin/modprobe)
==17418== by 0x804B0CC: (within /sbin/modprobe)
==17418== by 0x804B074: (within /sbin/modprobe)
==17418== by 0x804B803: (within /sbin/modprobe)
==17418== by 0x804C1BC: (within /sbin/modprobe)
==17418== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17418==
==17418==
==17418== 1,470 (12 direct, 1,458 indirect) bytes in 1 blocks are definitely los
t in loss record 9 of 13
==17418== at 0x4021858: malloc (vg_replace_malloc.c:207)
==17418== by 0x80499C1: (within /sbin/modprobe)
==17418== by 0x804B30F: (within /sbin/modprobe)
==17418== by 0x804B074: (within /sbin/modprobe)
==17418== by 0x804B803: (within /sbin/modprobe)
==17418== by 0x804C1BC: (within /sbin/modprobe)
==17418== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17418==
==17418==
==17418== 378 (59 direct, 319 indirect) bytes in 1 blocks are definitely lost in
loss record 10 of 13
==17418== at 0x4021858: malloc (vg_replace_malloc.c:207)
==17418== by 0x8049A7E: (within /sbin/modprobe)
==17418== by 0x804A185: (within /sbin/modprobe)
==17418== by 0x804C665: (within /sbin/modprobe)
==17418== by 0x4040F6F: (below main) (in /lib/libc-2.6.so)
==17418==
==17418== LEAK SUMMARY:
==17418== definitely lost: 1,061 bytes in 46 blocks.
==17418== indirectly lost: 2,475 bytes in 146 blocks.
==17418== possibly lost: 0 bytes in 0 blocks.
==17418== still reachable: 0 bytes in 0 blocks.
==17418== suppressed: 0 bytes in 0 blocks.
==17332==
==17332== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 49 from 1)
==17332== malloc/free: in use at exit: 90,891 bytes in 1,767 blocks.
==17332== malloc/free: 1,837 allocs, 70 frees, 103,856 bytes allocated.
==17332== For counts of detected errors, rerun with: -v
==17332== searching for pointers to 1,767 not-freed blocks.
==17332== checked 534,492 bytes.
==17332==
==17332== LEAK SUMMARY:
==17332== definitely lost: 0 bytes in 0 blocks.
==17332== possibly lost: 0 bytes in 0 blocks.
==17332== still reachable: 90,891 bytes in 1,767 blocks.
==17332== suppressed: 0 bytes in 0 blocks.
==17332== Reachable blocks (those to which a pointer was found) are not shown.
==17332== To see them, rerun with: --leak-check=full --show-reachable=yes
내용이 중복되어서
내용이 중복되어서 삭제 합니다.
valgrind 를 사용해보니까요..
modprobe "module" 처럼
뭔가 module을 하나 올리면,,항상 Memory Leak이 있는 것 처럼 보이네요.
처음에는 제 module이 정말 뭔가 이상한가 싶었는데요..
이젠 Valgrind가 module을 올릴때 뭔가 잘못계산하는 게 아닌가 싶기도 하네요.
비슷한 경험하신 분 계시면,,,조언 부탁드리겠습니다. ^^
댓글 달기