Solaris 内存泄漏调试(dbx)

转自:http://hi.baidu.com/askc037/blog/item/3b20e0cd1d2cea570eb345e1.html

 

 

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void foo()
{
    char *p = NULL;
    p = (char *)malloc(1);
}

class LeakClass
{
    public:
        LeakClass()
        {
            cout<<"No Parameter Constructor"<<endl;        
            foo();
        }
        
        LeakClass(const char *name)
        {
            cout<<"Parameter is:"<<name<<endl;
        }
};

int main(int argc, char **argv)
{
    LeakClass *P = NULL;
    cout << "Begin..." <<endl;
    sleep(10);
    while (1)
    {
        //foo();        
        P = new LeakClass();
        P = new LeakClass("Hello");
        delete(P);
        sleep(10);
        //break;
    }
    //cout << "End...Sleep" <<endl;    
    //sleep(50);
    return 0;
}

-----------------------------------
root@MassonSolaris:~/Desktop/MyDtrace# dbx ./a.out 
For information about new features see `help changes'
To remove this message, put `dbxenv suppress_startup_message 7.6' in your .dbxrc
Reading a.out
Reading ld.so.1
Reading libumem.so.1
Reading libCstd.so.1
Reading libCrun.so.1
Reading libm.so.2
Reading libc.so.1
(dbx) check -leaks
leaks checking - ON
(dbx) dbxenv rtc_mel_at_exit verbose
(dbx) run
Running: a.out 
(process id 1686)
Reading rtcapihook.so
Reading libdl.so.1
Reading rtcaudit.so
Reading libmapmalloc.so.1
Reading libgen.so.1
Reading rtcboot.so
Reading librtc.so
RTC: Enabling Error Checking...
RTC: Running program...
Begin...
No Parameter Constructor
Parameter is:Hello
Checking for memory leaks...

Actual leaks report    (actual leaks:            2 total size:          2 bytes)

Memory Leak (mel):
Found leaked block of size 1 byte at address 0x8067c50
At time of allocation, the call stack was:
    [1] operator new() at 0xbd90662b 
    [2] main() at line 34 in "MemoryLeak07.cpp"

Memory Leak (mel):
Found leaked block of size 1 byte at address 0x8067c70
At time of allocation, the call stack was:
    [1] foo() at line 9 in "MemoryLeak07.cpp"
    [2] LeakClass::LeakClass() at line 18 in "MemoryLeak07.cpp"
    [3] main() at line 34 in "MemoryLeak07.cpp"



Possible leaks report (possible leaks:          0 total size:          0 bytes)



execution completed, exit code is 0
(dbx) 
---------------------------------
root@MassonSolaris:~/Desktop/MyDtrace# export LD_AUDIt=/opt/SUNWspro/lib/rtcaudit.so;
root@MassonSolaris:~/Desktop/MyDtrace# export LD_AUDIT=/opt/SUNWspro/lib/rtcaudit.so;
root@MassonSolaris:~/Desktop/MyDtrace# echo $LD_AUDI

root@MassonSolaris:~/Desktop/MyDtrace# ps -a
   PID TTY         TIME CMD
1738 pts/2       0:00 a.out
588 ?           0:00 <defunct>
688 pts/2       1:23 gedit
1739 pts/3       0:00 ps
root@MassonSolaris:~/Desktop/MyDtrace# dbx ./a.out 1738
For information about new features see `help changes'
To remove this message, put `dbxenv suppress_startup_message 7.6' in your .dbxrc
Reading a.out
Reading ld.so.1
Reading libumem.so.1
Reading libCstd.so.1
Reading libCrun.so.1
Reading libm.so.2
Reading libc.so.1
Reading rtcaudit.so
Reading libmapmalloc.so.1
Reading libgen.so.1
Reading libdl.so.1
Reading rtcboot.so
Reading librtc.so
Attached to process 1738
stopped in __nanosleep at 0xd07846f5
0xd07846f5: __nanosleep+0x0015:    jae      __nanosleep+0x23    [ 0xd0784703, .+0xe ]
Current function is main
   37           sleep(10);
dbx: internal warning: set_error_limit called too early
(dbx) dbxenv mt_sync_tracking off
(dbx) check -leaks
leaks checking - ON
RTC: Enabling Error Checking...
RTC: Running program...
(dbx) showleaks -v -a
Checking for memory leaks...

Actual leaks report    (actual leaks:            2 total size:          2 bytes)

Memory Leak (mel):
Found leaked block of size 1 byte at address 0x8067c88
At time of allocation, the call stack was:
    [1] operator new() at 0xd089662b 
    [2] main() at line 34 in "MemoryLeak07.cpp"

Memory Leak (mel):
Found leaked block of size 1 byte at address 0x8067ca8
At time of allocation, the call stack was:
    [1] foo() at line 9 in "MemoryLeak07.cpp"
    [2] LeakClass::LeakClass() at line 18 in "MemoryLeak07.cpp"
    [3] main() at line 34 in "MemoryLeak07.cpp"



Possible leaks report (possible leaks:          0 total size:          0 bytes)


(dbx) 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值