[C언어] malloc에서 free가 안될경우?

antz의 이미지

프로그램은 pthread를 사용하는 프로그램입니다.

pthread_detach()를 사용해서 thread를 소멸시키고,

다음 내용은 하나의 쓰레드 함수 중 에서 발생됩니다.

=====================================
leakbug 라이브러리로 메모리 leak을 잡고 있습니다.
처음 격는 경우인데 free가 안되는군요.

디버그 메세지와 free하는 곳 소스 일부를 올립니다.

혹시 짐작이라도 되시면 답변 부탁드립니다.

DEC => 134810112 = 0x8090a00 <= HEX

보다 보니 이상한게 있어서 추가 합니다.

함수는 달라도 같은 처리 루틴 안에 있는 다른 변수가
같은 번지에 쓰이네요.
<LB> indexsearch.c:1241 - 0x8090a00 (1428 bytes)
<LB> indexsearch.c:117 - 0x8090a00 (40064 bytes)
둘다 free가 안되네요

Quote:
111111111111111 [0x134810112] size=40064
222222222222. [0x134810112] size=40064
nCountD=313, nCountK=41
333333333333. [0x134810112] size=40064

SearchIndexBinDouble : Memory Leak ====================================
<LB> Displaying leaked memory:
<LB> indexsearch.c:1230 - 0x8091290 (168 bytes)
<LB> indexsearch.c:1241 - 0x8090a00 (1428 bytes)
<LB> indexsearch.c:117 - 0x8090a00 (40064 bytes)
<LB> indexsearch.c:219 - 0x809a688 (5248 bytes)
<LB> indexsearch.c:1370 - 0x41131008 (2965920 bytes)
getListDoubleBuffer SearchIndex nCount = [30895]

getListBusiness2 : Memory Leak ====================================
<LB> Displaying leaked memory:
<LB> indexsearch.c:1230 - 0x8091290 (168 bytes)
<LB> indexsearch.c:1241 - 0x8090a00 (1428 bytes)
<LB> indexsearch.c:117 - 0x8090a00 (40064 bytes)
<LB> indexsearch.c:219 - 0x809a688 (5248 bytes)
<LB> datafind.c:2666 - 0x80e4058 (1440 bytes)

SearchKeyword : Memory Leak ====================================
<LB> Displaying leaked memory:
<LB> indexsearch.c:1230 - 0x8091290 (168 bytes)
<LB> indexsearch.c:1241 - 0x8090a00 (1428 bytes)
<LB> indexsearch.c:117 - 0x8090a00 (40064 bytes)
<LB> indexsearch.c:219 - 0x809a688 (5248 bytes)


        if (nCountD > 0)
        {
            printf("333333333333. [0x%d] size=%d\n", pBufferD, nCountD*sizeof(IndexPremium));
            free(pBufferD);
        }

antz의 이미지

이것 저것 찾다 메모리 누수 관련 좋은 정보가 있어서 URL남깁니다.

http://www.whiterabbitpress.com/lg/issue81/kurup.html

다른 분들도 좋은 정보 있으면 부탁드리겠습니다.

서지훈의 이미지

malloc()으로 잡은 메모리를 subfunction 에서 realloc()으로 재조정 하였을때, segmentation나는건 봤어도...
그냥 malloc()으로 잡은게 free()가 안된다면...
소스에 이상이 없다면 컴파일러 문제라고밖에...

소스를 오픈해 주시질 않으시니 더 이상 무어라 말씀을 드리긴 곤란하고...
찬찬히 선언한 부분과 포인터를 사용하는 부분에서 다른 작업을 해준게 없는지를 확인 해보세요.
free()를 중복 한다던지...-_-ㅋ

그리고, 포인터는 함수 파일에 상관없이 항상 똑같은 곳을 가르키게 됩니다.^^
함수가 틀리고, 파일이 틀리다고 포인터가 가르키는 곳이 틀리면 그건 아무런 의미가 없어 지겠죠^^
달라 진다면 포인터의 포인터는 달라 지겠지만.

<어떠한 역경에도 굴하지 않는 '하양 지훈'>

#include <com.h> <C2H5OH.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);

익명 사용자의 이미지

링크된 페이지에 checkergcc가 언급이 안되어있군요. valgrind덕에 전 요즘은
안쓰고있지만 역시나 강력하고 훌륭한 툴...
그외에 상용으로 언급된 purify는 말할필요가 없는 강력한 툴이죠? ^^*

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.