malloc 함수를 사용하여 연결된 목록의 노드에 메모리를 할당하려고합니다. 그러나 malloc 호출에서 세그먼트 화 오류가 발생합니다. valgrind가 생성 한 보고서를 이해할 수 없습니다.C에서 malloc의 메모리 할당 오류를 추적하는 방법
==28861== total heap usage: 76 allocs, 73 frees, 14,544 bytes allocated
==28861==
==28861== 48 bytes in 1 blocks are still reachable in loss record 1 of 3
==28861== at 0x4A0610C: malloc (vg_replace_malloc.c:195)
==28861== by 0x4027A2: create_server_entry_into_connection_list (all.c:734)
==28861== by 0x401BF8: server_call (all.c:410)
==28861== by 0x40103F: main (all.c:108)
==28861==
==28861== 568 bytes in 1 blocks are still reachable in loss record 2 of 3
==28861== at 0x4A0610C: malloc (vg_replace_malloc.c:195)
==28861== by 0x3E3C260309: __fopen_internal (in /lib64/libc-2.5.so)
==28861== by 0x4012E2: myip (all.c:174)
==28861== by 0x400FE7: main (all.c:101)
==28861==
==28861== 1,024 bytes in 1 blocks are still reachable in loss record 3 of 3
==28861== at 0x4A0610C: malloc (vg_replace_malloc.c:195)
==28861== by 0x4027B3: create_server_entry_into_connection_list (all.c:736)
==28861== by 0x401BF8: server_call (all.c:410)
==28861== by 0x40103F: main (all.c:108)
==28861==
==28861== LEAK SUMMARY:
==28861== definitely lost: 0 bytes in 0 blocks
==28861== indirectly lost: 0 bytes in 0 blocks
==28861== possibly lost: 0 bytes in 0 blocks
==28861== still reachable: 1,640 bytes in 3 blocks
==28861== suppressed: 0 bytes in 0 blocks
==28861==
==28861== For counts of detected and suppressed errors, rerun with: -v
==28861== Use --track-origins=yes to see where uninitialised values come from
==28861== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 4 from 4)
Segmentation fault
누구든지 이러한 오류의 원인이 될 수 있습니다.
라인 번호는 좋은 시작입니다. 우리는 코드를 모릅니다. – Ben
실제로 많은 파일이 연결된 매우 큰 코드로 여기에 게시 할 수 없습니다. 나는 그 선들을 점검했지만 그 변수들을 깔끔하게 사용하는 것처럼 보입니다. 또한 valgrind 보고서에서 여전히 실행 가능 플래그가 실행되는 동안 코드가 엉망이되어서는 안되지만 여전히 seg 오류가 발생했습니다. – Ninad