Problem:

  • Product Name: Visibroker
  • Product Version: any
  • Platform: Solaris
How do you check for a memory leak in an application/process?

Resolution:

There are two methods which can be used to check for memory leak in Solaris.

Method 1: This is the most easy way to check for memory leak but may not be comprehensive.

1.   Run the application using "dbx" as shown below
      $ dbx <application>

2.   Inside dbx check for memory usage.
      > check -memuse

If there are leaks in the application, we will get a table like the following:

        Total Size Num of Leaked Blocks Block Address Allocation call stack
        ========== ====== =========== ====================
        8 1 0×80688a8 func2 < func1 < func < main


The table shows memory leak of 8 bytes in main>func>func1>func2 function.


Method 2: This is the preferred way to check for memory leak.

1.   Load LIBUMEM before running an application.
      $ export LD_PRELOAD=libumem.so
      $ export UMEM_DEBUG=default

2.   Execute/Run the Application for an estimated 30 mins to stablize the memory usage.
3.   Generate core from process
      $ gcore <pid>

4.   Do the following to analyse the core file for memory leaks:
      $ mdb <core file>
      Loading modules: [ libumem.so.1 libc.so.1 ld.so.1 ]
      > ::findleaks –dv


Example output below shows no memory leak in osagent

       $ export LD_PRELOAD=libumem.so
       $ export UMEM_DEBUG=default
       $ osagent -p 15000 -ls 1 l oa &
       [3] 4407
       $ gcore 4407
       gcore: core.4407 dumped
       $ mdb core.4407
       Loading modules: [ libumem.so.1 libc.so.1 ld.so.1 ]


       > ::findleaks -dv
       findleaks:                maximum buffers => 732
       findleaks:                 actual buffers => 573
       findleaks:
       findleaks:             potential pointers => 158407
       findleaks:                     dismissals => 100952        (63.7%)
       findleaks:                         misses => 54735         (34.5%)
       findleaks:                           dups => 2147          ( 1.3%)
       findleaks:                        follows => 573           ( 0.3%)
       findleaks:
       findleaks:              elapsed wall time => 0 seconds
       findleaks:


       CACHE     LEAKED   BUFCTL CALLER
       ----------------------------------------------------------------------
          Total       0 buffers, 0 bytes
             

If there are memory leaks, “Total” will give the number of buffers/bytes leaked and the function calls where memory leak occur will also be shown.