Valgrind에서 alloc 갯수가 다릅니다.
글쓴이: ijs0430 / 작성시간: 수, 2017/05/17 - 7:18오후
valgrind에서 아주 간단한 코드를 작성했어요.
#include <stdio.h> #include <stdlib.h> int main() { int i; char *ch; i=100; printf("%d", i"); ch=malloc(10); return(0); }
작성해서 컴파일 하고 valgrind 돌려서 leak 부분 확인해보았는데
heap summary 부분에서 보면 계속 total heap usage : 2 allocs, 1 frees 라고 뜹니다.
저는 malloc 해준 부분이 한 군데 밖에 없는데 free는 당연히 안해주었고
그래서 1 alloc, 0 free라고 떠야 맞다고 생각하는데
이부분에 대해서 아시는 분 자세히 설명좀 부탁드립니다.
Forums:
일단 올려주신 코드에 syntax error 있고요.
일단 올려주신 코드에 syntax error 있고요.
이렇게 나오네요.
저는 왜 자꾸 malloc이 2개라고 뜨는지 혹시 이유 아시나여 ㅠㅠㅠ
valgrind --leak-check=full --leak-resolution=high ./a.out
==19779== Memcheck, a memory error detector==19779== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==19779== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info==
19779== Command: ./a.out==19779== 100==19779== ==19779== HEAP SUMMARY:==19779== in use at exit: 10 bytes in 1 blocks==19779==
total heap usage: 2 allocs, 1 frees, 1,034 bytes allocated==19779== ==19779== 10 bytes in 1 blocks are definitely lost in loss record 1 of 1==19779== at 0x402E23C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)==19779== by 0x804846F: main (in /home/tos/a.out)==19779== ==19779== LEAK SUMMARY:==19779== definitely lost: 10 bytes in 1 blocks==19779== indirectly lost: 0 bytes in 0 blocks==19779== possibly lost: 0 bytes in 0 blocks==19779== still reachable: 0 bytes in 0 blocks==19779== suppressed: 0 bytes in 0 blocks
음
파일 저장을 다시 해서 컴파일 해보시고 테스트 해보세요. 그리고 동일한 증상이 발생하면 코드 새로 올려주셔야 합니다. 올려주신 소스와 @ijs0430 님이 테스트 하는 코드가 다를겁니다.
소곤소곤
음..
http://stackoverflow.com/questions/38165164/valgrind-stdio-hs-function-puts-allocates-memory
glibc-2.22 부터 printf 와 같이 stdout 으로 출력할 때..
내부적으로 mmap 대신 malloc 을 사용하도록 바뀌었다는 것 같습니다.
glibc-2.19 를 쓰는 x86_64 와 arm 에서는 malloc 을 사용하지 않는데..
glibc-2.23 을 쓰는 i686 에서는 malloc 이 한 번 발생하네요.
printf 대신 fputs, puts 로 바꿔도 마찬가지입니다.
아래는 glibc-2.19 (x86_64).. (arm 도 비슷)
이건 glibc-2.23 (i686) ..
되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』
댓글 달기