티스토리 툴바

   개발자 로니강(Ronie.Kang)  
Front Page
Tag | Location | Media | Guestbook | Admin   
 
Finding Memory Leaks Using the CRT Library
Visual Studio를 사용시 아래 링크를 참조하면 memory leak을 쉽게 잡을 수 있습니다.

http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx


Tool을 이용하지 못 하는 경우에는,

malloc이나 free가 호출 될때 블럭 사이즈와 counter를 계산하여 free가 되지 않은 곳에
위치를 잡아두고, 프로그램이 끝날 때 출력하면 memory leak을 쉽게 잡을 수 있습니다.


static void *malloc_dbg(size)
{
    totalMemoryUsage += size;
    return malloc(size);
}

static void free_dbg(void *dst, int size)
{
    totalMemoryUsage -= size;
    free(dst);
}

void reportMemoryReport()
{
     if (!totalMemoryUsage) {
         return;
     }
     // memory leak detected! 
     //
}

뭐 대충 이런거고요.

좀도 지속적으로 써먹을꺼면, malloc 할때 #define로 malloc_dbg를 좀더 다듬어 주면 되겠네요.
malloc 위치라던지 이런걸 받아 테이블에 기억해두고 나중에 해제가 되면 테이블에서 삭제.
추후 리포트에서 memory 가 해제되지 않을을 때 출력.


기초적인 내용을 그냥 끄적 해봤습니다.

하나더 magic code를 malloc시에 넣어 buffer overflow가 발생, 메모리 경계가 넘어가는걸 체크 해보는 방법도 좋습니다.
크리에이티브 커먼즈 라이선스
Creative Commons License
Commented by hostels beijing at 2011/10/22 12:12  r x
Thank you for sharing, I really enjoyed your posts and pictures they were great! I think that all of us who follow this blog have that same feeling that you got from visiting. It is very special and the people are wonderful.

name    password    homepage
 hidden


BLOG main image
개발자 로니의 스토리.... 삽질, 날샘, 야근, 개발, 자취생, 일상, 프로그래밍 개발, 등등등....
 Notice
 Category
분류 전체보기 (191)
매일매일갱생 (76)
아이폰 (0)
Books (3)
Programming (86)
BroadCast (12)
Personal Projects (6)
유용한 프로그램 (0)
비공개 (0)
 TAGS
아이폰 SIP itunes 동기화 토렌토 It 국내 토렌토 인터넷전화 ubuntu MB 바보짓 sip 해킹 malloc iphone 개발환경 myLG070 usb 인식 실수 Porter-Duff warning C++ 조중동 torrent 용자 가카 Linux 벨소리 변경 메모리 누수 C 강남역 directfb iPhone 미라지 벨소리 M480 빵꾸똥꾸 iTunes arduino uno Memory Leak 스마트폰 아이튠즈 VirtualBox
 Calendar
«   2012/01   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
 Recent Entries
Finding Memory Leaks Using t.. (1)
Program Arduino with AVR-GCC
새로운 장난감....
ATMEGA328P-PU
Arduino uno 간단한 보드 설명.
퇴근길 강남역에서 만난 도인?.. (1)
xper 5월 정기모임이 일정 (1)
국내 토렌토 주소 모음
미라지(SKT) M480 벨소리 변경..
myLG070 sip 추출하기 (3)
warning: braces around scala..
 Recent Comments
java/lang/Object j..
sumin - 2011
Common persons do n..
Research paper - 2011
At the essay writin..
buy essay - 2011
The hard working pe..
dissertation service - 2011
Pretty good text re..
buy essay - 2011
Yeah absolutely ve..
resume writing service - 2011
You know that you h..
buy a research paper - 2011
In fact, some stude..
Term Paper Online - 2011
Buy an essay or wri..
buy essays - 2011
Even thesis writing..
thesis - 2011
You do a great job...
term paper - 2011
 Recent Trackbacks
COFDM 방식에서의 Bi..
Steve Yoon's log
다중포인터 읽기
.
 Archive
2011/09
2010/06
2010/05
2010/04
2010/02
2010/01
2009/12
2009/11
2009/10
2009/09
 Link Site
zextor
괴짜 프로그래머의 일상사~@@
Gag & Peace, and more..
Kazakhstan Almaty.......
Min-A
Sadgarret
Steve Yoon's log
가슴 뛰는 삶을 살아라
오스틴 파워
GUI sin
melanie parker_Lady
제레미의 TV 2.0 이야기..
 Visitor Statistics
Total : 84,505
Today : 3
Yesterday : 30
rss