kim@ubuntu:~/Desktop$ cat ValGrindTest.c
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
typedef struct _test_t {
int data;
}test_t;
int main(void)
{
test_t *test = NULL;
test = (test_t*)malloc(sizeof(test_t));
test->data = 3;
printf("test->data = %d\n", test->data);
return 0;
}
kim@ubuntu:~/Desktop$ valgrind ./ValGrindTest --tool=memcheck --leck-check=summary
==3775== Memcheck, a memory error detector
==3775== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==3775== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==3775== Command: ./ValGrindTest --tool=memcheck --leck-check=summary
==3775==
test->data = 3
==3775==
==3775== HEAP SUMMARY:
==3775== in use at exit: 4 bytes in 1 blocks
==3775== total heap usage: 2 allocs, 1 frees, 1,028 bytes allocated
==3775==
==3775== LEAK SUMMARY:
==3775== definitely lost: 4 bytes in 1 blocks [4byte 짜리 1개 블럭이 현재 메모리 누수]
==3775== indirectly lost: 0 bytes in 0 blocks
==3775== possibly lost: 0 bytes in 0 blocks
==3775== still reachable: 0 bytes in 0 blocks
==3775== suppressed: 0 bytes in 0 blocks
==3775== Rerun with --leak-check=full to see details of leaked memory
==3775==
==3775== For counts of detected and suppressed errors, rerun with: -v
==3775== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
[코드 수정 후]
kim@ubuntu:~/Desktop$ valgrind ./ValGrindTest --tool=memcheck --leck-check=summary
==3824== Memcheck, a memory error detector
==3824== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==3824== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==3824== Command: ./ValGrindTest --tool=memcheck --leck-check=summary
==3824==
test->data = 3
==3824==
==3824== HEAP SUMMARY:
==3824== in use at exit: 0 bytes in 0 blocks
==3824== total heap usage: 2 allocs, 2 frees, 1,028 bytes allocated
==3824==
==3824== All heap blocks were freed -- no leaks are possible
==3824==
==3824== For counts of detected and suppressed errors, rerun with: -v
==3824== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
'언어 > c언어' 카테고리의 다른 글
c언어 affine (0) | 2017.08.23 |
---|---|
회전 (0) | 2017.08.10 |
자료형(sizeof) (0) | 2017.08.08 |
오버 플로우 됬는지 확인하는 코드 (c언어) (0) | 2017.07.30 |
추가할 임시 코드 [ 계산기 ] (0) | 2017.07.30 |