valgrind 리포트 결과 보았는데.. 디버깅이 어렵네요 도움좀 부탁드려요 ㅠㅠ
프로그램에 메모리릭이 발생하여 valgrind를 사용하여 체크하였습니다.
아래가 리포트 결과 이며 오류발생하는 함수 체크해보았는데 아무런 증상이 없네요..
아래 리포트 결과를 정확히 어떻게 받아들여야하며.. 어느부분을 체크해봐야 하는지.. 도움좀주세요
==32210== ERROR SUMMARY: 52 errors from 12 contexts (suppressed: 79 from 2)
==32210== malloc/free: in use at exit: 17,334,259 bytes in 11,577 blocks.
==32210== malloc/free: 36,418 allocs, 24,841 frees, 21,007,692 bytes allocated.
==32210== For counts of detected errors, rerun with: -v
==32210== searching for pointers to 11,577 not-freed blocks.
==32210== checked 193,879,836 bytes.
==32210==
==32210==
==32210== 12 bytes in 1 blocks are still reachable in loss record 1 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x804F314: ntt_create (ntt.c:76)
==32210== by 0x804C681: healthcheck_init (hcheck_manager.c:51)
==32210== by 0x804FAA6: main (main.c:125)
==32210==
==32210==
==32210== 20 bytes in 1 blocks are still reachable in loss record 2 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x804F27A: ntt_node_create (ntt.c:54)
==32210== by 0x804F550: ntt_insert (ntt.c:165)
==32210== by 0x804CB3D: add_client (hcheck_manager.c:167)
==32210== by 0x805101D: chk_protocol (main.c:675)
==32210== by 0x80500DE: established_proc (main.c:278)
==32210== by 0x804FDFD: running_server (main.c:220)
==32210== by 0x804FC3C: main (main.c:173)
==32210==
==32210==
==32210== 28 bytes in 1 blocks are still reachable in loss record 3 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x8049635: db_pool_callback_init (db_manager.c:56)
==32210== by 0x80495B2: db_pool_init (db_manager.c:77)
==32210== by 0x804954E: initialize_db (db_manager.c:32)
==32210== by 0x804F9CC: main (main.c:100)
==32210==
==32210==
==32210== 156 (36 direct, 120 indirect) bytes in 1 blocks are definitely lost in loss record 4 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x4120713: (within /lib/libc-2.7.so)
==32210== by 0x4120E73: __nss_database_lookup (in /lib/libc-2.7.so)
==32210== by 0x7A0BF4B: ???
==32210== by 0x7A0CCEC: ???
==32210== by 0x40DA281: getpwuid_r (in /lib/libc-2.7.so)
==32210== by 0x4041D3D: (within /usr/lib/libpq.so.5.1)
==32210== by 0x402C819: (within /usr/lib/libpq.so.5.1)
==32210== by 0x403107E: (within /usr/lib/libpq.so.5.1)
==32210== by 0x4031108: (within /usr/lib/libpq.so.5.1)
==32210== by 0x40319B4: PQsetdbLogin (in /usr/lib/libpq.so.5.1)
==32210== by 0x80497D9: db_pool_pgsql_alloc (db_manager.c:114)
==32210==
==32210==
==32210== 40 bytes in 5 blocks are indirectly lost in loss record 5 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x41202AB: __nss_lookup_function (in /lib/libc-2.7.so)
==32210== by 0x7A0BF6B: ???
==32210== by 0x7A0CCEC: ???
==32210== by 0x40DA281: getpwuid_r (in /lib/libc-2.7.so)
==32210== by 0x4041D3D: (within /usr/lib/libpq.so.5.1)
==32210== by 0x402C819: (within /usr/lib/libpq.so.5.1)
==32210== by 0x403107E: (within /usr/lib/libpq.so.5.1)
==32210== by 0x4031108: (within /usr/lib/libpq.so.5.1)
==32210== by 0x40319B4: PQsetdbLogin (in /usr/lib/libpq.so.5.1)
==32210== by 0x80497D9: db_pool_pgsql_alloc (db_manager.c:114)
==32210== by 0x80495F7: db_pool_init (db_manager.c:82)
==32210==
==32210==
==32210== 64 bytes in 1 blocks are still reachable in loss record 6 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x804D665: notice_check_init (notice_manager.c:33)
==32210== by 0x804FAE3: main (main.c:133)
==32210==
==32210==
==32210== 80 bytes in 5 blocks are indirectly lost in loss record 7 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x410F5D0: tsearch (in /lib/libc-2.7.so)
==32210== by 0x412026D: __nss_lookup_function (in /lib/libc-2.7.so)
==32210== by 0x7A0BF6B: ???
==32210== by 0x7A0CCEC: ???
==32210== by 0x40DA281: getpwuid_r (in /lib/libc-2.7.so)
==32210== by 0x4041D3D: (within /usr/lib/libpq.so.5.1)
==32210== by 0x402C819: (within /usr/lib/libpq.so.5.1)
==32210== by 0x403107E: (within /usr/lib/libpq.so.5.1)
==32210== by 0x4031108: (within /usr/lib/libpq.so.5.1)
==32210== by 0x40319B4: PQsetdbLogin (in /usr/lib/libpq.so.5.1)
==32210== by 0x80497D9: db_pool_pgsql_alloc (db_manager.c:114)
==32210==
==32210==
==32210== 106 bytes in 1 blocks are still reachable in loss record 8 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x804CBCE: add_client (hcheck_manager.c:175)
==32210== by 0x805101D: chk_protocol (main.c:675)
==32210== by 0x80500DE: established_proc (main.c:278)
==32210== by 0x804FDFD: running_server (main.c:220)
==32210== by 0x804FC3C: main (main.c:173)
==32210==
==32210==
==32210== 440 bytes in 1 blocks are still reachable in loss record 9 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x804C14D: tm_init (thread_manager.c:31)
==32210== by 0x804F946: main (main.c:84)
==32210==
==32210==
==32210== 500 bytes in 500 blocks are still reachable in loss record 10 of 22
==32210== at 0x4021E22: calloc (vg_replace_malloc.c:397)
==32210== by 0x4031823: (within /usr/lib/libpq.so.5.1)
==32210== by 0x4031997: PQsetdbLogin (in /usr/lib/libpq.so.5.1)
==32210== by 0x80497D9: db_pool_pgsql_alloc (db_manager.c:114)
==32210== by 0x80495F7: db_pool_init (db_manager.c:82)
==32210== by 0x804954E: initialize_db (db_manager.c:32)
==32210== by 0x804F9CC: main (main.c:100)
==32210==
==32210==
==32210== 3,168 bytes in 22 blocks are possibly lost in loss record 11 of 22
==32210== at 0x4021E22: calloc (vg_replace_malloc.c:397)
==32210== by 0x4010C7B: _dl_allocate_tls (in /lib/ld-2.7.so)
==32210== by 0x418A5A7: pthread_create@@GLIBC_2.1 (in /lib/libpthread-2.7.so)
==32210== by 0x804C215: tm_init (thread_manager.c:44)
==32210== by 0x804F946: main (main.c:84)
==32210==
==32210==
==32210== 20,000 bytes in 1 blocks are still reachable in loss record 12 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x80495A8: db_pool_init (db_manager.c:75)
==32210== by 0x804954E: initialize_db (db_manager.c:32)
==32210== by 0x804F9CC: main (main.c:100)
==32210==
==32210==
==32210== 21,776 (1,296 direct, 20,480 indirect) bytes in 9 blocks are definitely lost in loss record 13 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x4033DD8: PQmakeEmptyPGresult (in /usr/lib/libpq.so.5.1)
==32210== by 0x403D412: (within /usr/lib/libpq.so.5.1)
==32210== by 0x4032E17: (within /usr/lib/libpq.so.5.1)
==32210== by 0x4034A80: PQgetResult (in /usr/lib/libpq.so.5.1)
==32210== by 0x4034C92: (within /usr/lib/libpq.so.5.1)
==32210== by 0x8049BD4: db_pgsql_select (db_manager.c:227)
==32210== by 0x804B529: auth_check (client_manager.c:497)
==32210== by 0x805097C: con_protocol (main.c:470)
==32210== by 0x805026A: established_proc (main.c:309)
==32210== by 0x804FDFD: running_server (main.c:220)
==32210== by 0x804FC3C: main (main.c:173)
==32210==
==32210==
==32210== 2,048 bytes in 4 blocks are indirectly lost in loss record 14 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x4031DE7: (within /usr/lib/libpq.so.5.1)
==32210== by 0x403D523: (within /usr/lib/libpq.so.5.1)
==32210== by 0x4032E17: (within /usr/lib/libpq.so.5.1)
==32210== by 0x4034A80: PQgetResult (in /usr/lib/libpq.so.5.1)
==32210== by 0x4034C92: (within /usr/lib/libpq.so.5.1)
==32210== by 0x8049BD4: db_pgsql_select (db_manager.c:227)
==32210== by 0x804B529: auth_check (client_manager.c:497)
==32210== by 0x805097C: con_protocol (main.c:470)
==32210== by 0x805026A: established_proc (main.c:309)
==32210== by 0x804FDFD: running_server (main.c:220)
==32210== by 0x804FC3C: main (main.c:173)
==32210==
==32210==
==32210== 18,432 bytes in 9 blocks are indirectly lost in loss record 15 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x4031CEB: (within /usr/lib/libpq.so.5.1)
==32210== by 0x403CF37: (within /usr/lib/libpq.so.5.1)
==32210== by 0x4032E17: (within /usr/lib/libpq.so.5.1)
==32210== by 0x4034A80: PQgetResult (in /usr/lib/libpq.so.5.1)
==32210== by 0x4034C92: (within /usr/lib/libpq.so.5.1)
==32210== by 0x8049BD4: db_pgsql_select (db_manager.c:227)
==32210== by 0x804B529: auth_check (client_manager.c:497)
==32210== by 0x805097C: con_protocol (main.c:470)
==32210== by 0x805026A: established_proc (main.c:309)
==32210== by 0x804FDFD: running_server (main.c:220)
==32210== by 0x804FC3C: main (main.c:173)
==32210==
==32210==
==32210== 27,333 bytes in 4,014 blocks are still reachable in loss record 16 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x40B745F: strdup (in /lib/libc-2.7.so)
==32210== by 0x403118A: (within /usr/lib/libpq.so.5.1)
==32210== by 0x40319B4: PQsetdbLogin (in /usr/lib/libpq.so.5.1)
==32210== by 0x80497D9: db_pool_pgsql_alloc (db_manager.c:114)
==32210== by 0x80495F7: db_pool_init (db_manager.c:82)
==32210== by 0x804954E: initialize_db (db_manager.c:32)
==32210== by 0x804F9CC: main (main.c:100)
==32210==
==32210==
==32210== 49,156 bytes in 1 blocks are still reachable in loss record 17 of 22
==32210== at 0x4021E22: calloc (vg_replace_malloc.c:397)
==32210== by 0x804F36B: ntt_create (ntt.c:87)
==32210== by 0x804C681: healthcheck_init (hcheck_manager.c:51)
==32210== by 0x804FAA6: main (main.c:125)
==32210==
==32210==
==32210== 149,500 bytes in 4,500 blocks are still reachable in loss record 18 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x4034007: (within /usr/lib/libpq.so.5.1)
==32210== by 0x403B0FB: (within /usr/lib/libpq.so.5.1)
==32210== by 0x403CBAC: (within /usr/lib/libpq.so.5.1)
==32210== by 0x4032E17: (within /usr/lib/libpq.so.5.1)
==32210== by 0x4033066: PQisBusy (in /usr/lib/libpq.so.5.1)
==32210== by 0x402E7A2: PQconnectPoll (in /usr/lib/libpq.so.5.1)
==32210== by 0x402F85F: (within /usr/lib/libpq.so.5.1)
==32210== by 0x4031A10: PQsetdbLogin (in /usr/lib/libpq.so.5.1)
==32210== by 0x80497D9: db_pool_pgsql_alloc (db_manager.c:114)
==32210== by 0x80495F7: db_pool_init (db_manager.c:82)
==32210== by 0x804954E: initialize_db (db_manager.c:32)
==32210==
==32210==
==32210== 256,000 bytes in 1,000 blocks are still reachable in loss record 19 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x403D905: initPQExpBuffer (in /usr/lib/libpq.so.5.1)
==32210== by 0x402F9F2: (within /usr/lib/libpq.so.5.1)
==32210== by 0x403184B: PQsetdbLogin (in /usr/lib/libpq.so.5.1)
==32210== by 0x80497D9: db_pool_pgsql_alloc (db_manager.c:114)
==32210== by 0x80495F7: db_pool_init (db_manager.c:82)
==32210== by 0x804954E: initialize_db (db_manager.c:32)
==32210== by 0x804F9CC: main (main.c:100)
==32210==
==32210==
==32210== 422,000 bytes in 500 blocks are still reachable in loss record 20 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x402F910: (within /usr/lib/libpq.so.5.1)
==32210== by 0x403184B: PQsetdbLogin (in /usr/lib/libpq.so.5.1)
==32210== by 0x80497D9: db_pool_pgsql_alloc (db_manager.c:114)
==32210== by 0x80495F7: db_pool_init (db_manager.c:82)
==32210== by 0x804954E: initialize_db (db_manager.c:32)
==32210== by 0x804F9CC: main (main.c:100)
==32210==
==32210==
==32210== 8,192,000 bytes in 500 blocks are still reachable in loss record 21 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x402F9DE: (within /usr/lib/libpq.so.5.1)
==32210== by 0x403184B: PQsetdbLogin (in /usr/lib/libpq.so.5.1)
==32210== by 0x80497D9: db_pool_pgsql_alloc (db_manager.c:114)
==32210== by 0x80495F7: db_pool_init (db_manager.c:82)
==32210== by 0x804954E: initialize_db (db_manager.c:32)
==32210== by 0x804F9CC: main (main.c:100)
==32210==
==32210==
==32210== 8,192,000 bytes in 500 blocks are still reachable in loss record 22 of 22
==32210== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==32210== by 0x402F9C2: (within /usr/lib/libpq.so.5.1)
==32210== by 0x403184B: PQsetdbLogin (in /usr/lib/libpq.so.5.1)
==32210== by 0x80497D9: db_pool_pgsql_alloc (db_manager.c:114)
==32210== by 0x80495F7: db_pool_init (db_manager.c:82)
==32210== by 0x804954E: initialize_db (db_manager.c:32)
==32210== by 0x804F9CC: main (main.c:100)
==32210==
==32210== LEAK SUMMARY:
==32210== definitely lost: 1,332 bytes in 10 blocks.
==32210== indirectly lost: 20,600 bytes in 23 blocks.
==32210== possibly lost: 3,168 bytes in 22 blocks.
==32210== still reachable: 17,309,159 bytes in 11,522 blocks.
==32210== suppressed: 0 bytes in 0 blocks.
모두 메모리릭 관련된 오류이네요. "...
모두 메모리릭 관련된 오류이네요.
"... blocks are still reachable ... " 은 할당받은 메모리를 프로그램이 끝날 때가지 해지하지 않았다는 말입니다.
코드의 어느 라인에서 할당받은 메모리인지는 by 로 시작하는 라인들을 보시면 나와있습니다.
연속된 by 는 "~ 에 의해 호출된" 이라고 해석하시면 됩니다.
"...blocks are indirectly lost ..." 은 할당받은 메모리를 해지하지 않고, 그 메모리를 가리키는 포인터의 값을 바꾸었다는 뜻입니다.
고로 그 메모리를 해지할 방법이 없어진겁니다.
그런 메모리 영역이 계속 쌓여가면 사용하지 않는 메모리를 재활용할 수 없으니 쓸데없이 메모리를 모두 써버릴 수도 있습니다.
"...blocks are definitely
"...blocks are definitely lost ..." 역시 "...blocks are indirectly lost ..." 와 비슷합니다.
그리고 메모리 릭이 발생하는 경우는 할당받은 메모리를 해지하지 않고, 그 메모리를 가리키는 포인터의 값을 바꾸는 경우 말고도
지역 변수 포인터가 스코프를 벗어나서 사라지는 경우도 있습니다.
댓글 달기