메인 함수에서 바로 리턴 했는데.. 메모리릭이 나오네요;;

lansea의 이미지

int main(void)
{
return 0;
}

소스는 위와 같구요..

valgrind --tool=memcheck --leak-check=yes --run-libc-freeres=no --show-reachable=yes VSIF
이렇게 valgrind로 메모리 릭 검사하니까
아래와 같이 나와요...
ㅡㅡ;; 어떻게 이럴수가 있죠?

1,001,510 바이트나 메모리가 새다니..
원인이 뭔지 아시는분 좀 알려주세요

------------------------------------------------------------------------------
==1296== Memcheck, a memory error detector.
==1296== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==1296== Using LibVEX rev 1658, a library for dynamic binary translation.
==1296== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==1296== Using valgrind-3.2.1, a dynamic binary instrumentation framework.
==1296== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==1296== For more details, rerun with: -v
==1296==
==1296==
==1296== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 14 from 1)
==1296== malloc/free: in use at exit: 1,001,510 bytes in 1 blocks.
==1296== malloc/free: 1 allocs, 0 frees, 1,001,510 bytes allocated.
==1296== For counts of detected errors, rerun with: -v
==1296== searching for pointers to 1 not-freed blocks.
==1296== checked 1,257,248 bytes.
==1296==
==1296== 1,001,510 bytes in 1 blocks are still reachable in loss record 1 of 1
==1296== at 0x40046FF: calloc (vg_replace_malloc.c:279)
==1296== by 0xBBB424: monstartup (in /lib/libc-2.5.so)
==1296== by 0x8049FDE: __gmon_start__ (in /home/cvod/bin/VSIF)
==1296== by 0xC54A71: (within /lib/libdl-2.5.so)
==1296== by 0xC5491E: (within /lib/libdl-2.5.so)
==1296== by 0x12AF02: call_init (in /lib/ld-2.5.so)
==1296== by 0x12B012: _dl_init (in /lib/ld-2.5.so)
==1296== by 0x11D84E: (within /lib/ld-2.5.so)
==1296==
==1296== LEAK SUMMARY:
==1296== definitely lost: 0 bytes in 0 blocks.
==1296== possibly lost: 0 bytes in 0 blocks.
==1296== still reachable: 1,001,510 bytes in 1 blocks.
==1296== suppressed: 0 bytes in 0 blocks.
------------------------------------------------------------------------------

jick의 이미지

일단 run-libc-freeres=no를 주셨으니 glibc에서 exit 때 시간절약을 위해서 불필요한 free는 과감하게 생략했을 테고요, 저 옵션을 yes로 주고 돌려보세요.

저 옵션을 no/yes로 줬을 때 바뀌는 부분은 glibc에서 알아서 하는 부분이니 glibc 자체를 debugging하시는 상황이 아니라면 그냥 무시하면 됩니다.

그나저나 라이브러리가 1M짜리를 한번에 할당해서 쓰다니 좀 의외네요. 함수 이름을 봐서는 gprof를 사용하도록 컴파일 옵션을 주신 게 아닌가 싶은데, 맞나요? gprof와 valgrind를 함께 사용하는 건 좀 어지러울 것 같은데요, 그냥 한번에 한쪽만 쓰는 게 서로간의 불필요한 간섭을 막아서 디버깅하기가 편할 것 같습니다.

auditory의 이미지

http://valgrind.org/docs/manual/faq.html#faq.exit_errors

Workaround for 1.1.X and later versions of Valgrind: use the --run-libc-freeres=no flag. You may then get space leak reports for glibc allocations (please don't report these to the glibc people, since they are not real leaks), but at least the program runs.


lansea의 이미지


jick 님이 적어주신 gprof를 보니까 갑자기 생각나더라구요 ㅎㅎ
gprof 때문에 적어둔 컴파일 옵션 빼고 하니까 잘됩니다~

run-libc-freeres=no 옵션을 넣은 이유는
pthread_create 안에서도 메모리 릭이 생기던데요.(아래 valgrind 결과..)
pthread_create 쪽 메모리 릭으로 검색해보니까 run-libc-freeres=no 를 옵션으로 하면
괜찮다고 해서 한거였는데요..옵션으로 넣어도 다 나오네요..ㅠㅠ

원래 소스에는 쓰레드 사용을 하거든요
제가 원글에 적어둔 부분의 메모리 릭때문에 그냥 main함수에서 바로 리턴해서 테스트 해본거였구요..

댓글 달아주신 분들 감사해요~ 덕분에 해결했습니다~ ㅎㅎㅎ



-------------------------------------------------------------------------------------------------
==4563== 544 bytes in 4 blocks are possibly lost in loss record 2 of 3
==4563== at 0x40046FF: calloc (vg_replace_malloc.c:279)
==4563== by 0x12D9E9: _dl_allocate_tls (in /lib/ld-2.5.so)
==4563== by 0xC5F9D6: pthread_create@@GLIBC_2.1 (in /lib/libpthread-2.5.so)
==4563== by 0x80F9A06: sysCreateThread (libsys_thread.c:24)
==4563== by 0x804AD53: init_threads (vsif_init.c:127)
==4563== by 0x804A0CB: main (vsif_main.c:77)
==4563==
==4563==
==4563== 1,024 bytes in 1 blocks are still reachable in loss record 3 of 3
==4563== at 0x40053C0: malloc (vg_replace_malloc.c:149)
==4563== by 0x400544A: realloc (vg_replace_malloc.c:306)
==4563== by 0xC5FDF0: pthread_create@@GLIBC_2.1 (in /lib/libpthread-2.5.so)
==4563== by 0x80F9A06: sysCreateThread (libsys_thread.c:24)
==4563== by 0x804AD53: init_threads (vsif_init.c:127)
==4563== by 0x804A0CB: main (vsif_main.c:77)

-------------------------------------------------------------------------------------------------
-----------------------------------------------
I'm free to be whatever I, whatever I Choose

-----------------------------------------------
I'm free to be whatever I, whatever I Choose

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.