Easy Memory Corruption Checking in Solaris

I've been using a shell script wrapper I wrote several years ago to make using libumem and watchmalloc memory corruption debugging features easy to use. The script is called memdbg and it can be used like so:

memdbg [memdbg options] <program and program args>

Example:

# Start the krb5kdc daemon with memory leak detection on
$ memdbg -l ./krb5kdc

# Check the kinit command for memory corruption
$ memdbg kinit tester
I also created a companion script called show_leaks which can report memory leaks found by libumem on a running process. Here's an example:
# Report memory leaks in kadmind when it's been started with memdbg -l:
$ show_leaks kadmind
CACHE     LEAKED   BUFCTL CALLER
0818aa90     127 081a81b8 libkadm5srv.so.1`decrypt_key_data+0x42
08189710     254 0878ca18 libkdb.so.1`krb5_dbekd_def_decrypt_key_data+0x8d
08189a90     127 081f8998 libkdb.so.1`krb5_dbekd_def_decrypt_key_data+0x8d
0818a010     127 081ca110 libkdb.so.1`krb5_dbekd_def_decrypt_key_data+0x8d
------------------------------------------------------------------------
   Total     635 buffers, 48768 bytes

# See the stacks of all leaked allocs
$ show_leaks -v kadmind
CACHE     LEAKED   BUFCTL CALLER
0818aa90     127 081a81b8 libkadm5srv.so.1`decrypt_key_data+0x42
08189710     254 0878ca18 libkdb.so.1`krb5_dbekd_def_decrypt_key_data+0x8d
08189a90     127 081f8998 libkdb.so.1`krb5_dbekd_def_decrypt_key_data+0x8d
0818a010     127 081ca110 libkdb.so.1`krb5_dbekd_def_decrypt_key_data+0x8d
------------------------------------------------------------------------
   Total     635 buffers, 48768 bytes
======================= 081a81b8::bufctl_audit info ======================
            ADDR          BUFADDR        TIMESTAMP           THREAD
                            CACHE          LASTLOG         CONTENTS
         81a81b8          81ae280    e7d2112af0cb1                1
                          818aa90          815fcfc                0
                 libumem.so.1`umem_cache_alloc_debug+0x157
                 libumem.so.1`umem_cache_alloc+0x157
                 libumem.so.1`umem_alloc+0xd0
                 libumem.so.1`malloc+0x2d
                 libkadm5srv.so.1`decrypt_key_data+0x42
                 libkadm5srv.so.1`kadm5_randkey_principal_3+0x47d
                 chrand_principal3_2_svc+0x248
                 kadm_1+0x381
                 libnsl.so.1`_svc_prog_dispatch+0x18e
                 libnsl.so.1`svc_getreq_common+0xf5
                 libnsl.so.1`svc_getreq_poll+0x65
                 kadm_svc_run+0x169
                 main+0x22a4
                 _start+0x7d

======================= 0878ca18::bufctl_audit info ======================
etc...

I've blogged before about both libumem and watchmalloc (both are part of native Solaris). I will say at this point I use libumem much more because it doesn't slow down a program very much at least when using the default options or -l leak reporting. Every Solaris developer should be using this at some point in testing. I have found numerous memory handling bugs using these tools.

Here are the URLs/links to the scripts mentioned above:
https://blogs.oracle.com/wfiveash/resource/memdbg
https://blogs.oracle.com/wfiveash/resource/show_leaks
To use them, use the "save the link as" function of your browser, chmod u+x memdbg|show_leaks, place them in your PATH, then run. Happy bug hunting!!!
Comments:

Post a Comment:
Comments are closed for this entry.
About

user12615206

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
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
   
       
Today