How to fix still-reachable memory leak?

2,584 views
Skip to first unread message

Green Nancy

unread,
Oct 22, 2016, 5:35:55 AM10/22/16
to Dr. Memory Users
Hi,
    My program have many still-reachable memory leak, but DRmemory only show the address range. eg:

Error #76: REACHABLE LEAK 32768 direct bytes 0x0138ff30-0x01397f30 + 0 indirect bytes
<memory was allocated before tool took control>

Same program, same options run, reachable leak address different. I can not use address as breakpoint.  Any suggestion on how to fix this type of memory leak?


--
Best Regards,
Yu Rong Tan

Derek Bruening

unread,
Oct 22, 2016, 2:05:53 PM10/22/16
to drmemor...@googlegroups.com
I'm assuming this is on Windows.  The "memory was allocated before tool took control" means it is not coming from your code.  This is likely from Windows system libraries which allocate memory but do not free it (probably because it has a lifetime equal to the process lifetime).  This is almost certainly unrelated to your program and there is not much that can be done about it.  It is best to ignore it (and Dr. Memory should perhaps hide it by default: I filed https://github.com/DynamoRIO/drmemory/issues/1922).

--

---
You received this message because you are subscribed to the Google Groups "Dr. Memory Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drmemory-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

nancygreen

unread,
Oct 23, 2016, 11:25:05 PM10/23/16
to Dr. Memory Users
Thank you for your info, Sir!

There are 91756 bytes of still-reachable allocations(65 unique,   160 total,  91756 byte(s) of still-reachable allocation(s) ). Total 63571 bytes of Reported <memory was allocated before tool took control> kind of still-reachable allocations which you said that beyond programmer control. I care about the lefting reachable LEAK, any hints to find it?

I had thought all still-reachable allocations are programming leak, I have a stack to store some malloc memory allocation address, and forget to release them in time. Thanks to this tool to notice me to check known memory allocation stack design.  I believe there still have some other unknown memory allocation design in the program which may cause that reachable leak. How can I find it?
To unsubscribe from this group and stop receiving emails from it, send an email to drmemory-user...@googlegroups.com.

Derek Bruening

unread,
Oct 27, 2016, 1:51:36 PM10/27/16
to drmemor...@googlegroups.com
Please see http://drmemory.org/docs/page_leaks.html which explains how still-reachable memory is not normally considered a true leak.

On Windows, Dr. Memory is not able to start executing your program until some of the system libraries have already initialized and allocated some memory on the heap.  Again, this is typically unrelated to your app.

You could try running like this with an earlier takeover, replacing "yourapp.exe" of course:

% bin/drmemory -show_reachable -dr_ops -early_inject -- dynamorio/bin32/create_process.exe yourapp.exe

That is not guaranteed to execute all apps (which is why it's not the default) but if it works it could give a more accurate picture of the system library allocations.

- Derek

To unsubscribe from this group and stop receiving emails from it, send an email to drmemory-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to drmemory-users+unsubscribe@googlegroups.com.

nancygreen

unread,
Nov 3, 2016, 8:25:00 AM11/3/16
to Dr. Memory Users
Thank you for your infos!

Would you please tell what's the condition that app should have to meet those options? Even a simple "helloworld.exe" hit the following error.

C:\Program Files (x86)\Dr. Memory\bin>drmemory.exe  -show_reachable -dr_ops -early_inject -- dynamo
rio/bin32/create_process.exe c:\helloworld.exe
ERROR: failed to create process (err=3) for "C:\Program Files (x86)\Dr. Memory\bin\dynamorio\bin32\
create_process.exe":

<press enter to dismiss>


I understand reachable leak are not app leak in drmemory design. But in reality, there really some app leak belongs to reachable leak. Maybe that is drmemory bug.  I have no time to mini reproduce testcase for you.  If you interest, you can see (https://github.com/svn2github/open64-trunk) osprey/common/util/mempool.h,  memory.c  if I forget to delete the pool or pop one by one, that memory leak belongs to reachable leak.

Derek Bruening

unread,
Nov 3, 2016, 10:16:15 AM11/3/16
to drmemor...@googlegroups.com
On Thu, Nov 3, 2016 at 8:25 AM, nancygreen <nancyd...@gmail.com> wrote:
Would you please tell what's the condition that app should have to meet those options? Even a simple "helloworld.exe" hit the following error.

C:\Program Files (x86)\Dr. Memory\bin>drmemory.exe  -show_reachable -dr_ops -early_inject -- dynamo
rio/bin32/create_process.exe c:\helloworld.exe
ERROR: failed to create process (err=3) for "C:\Program Files (x86)\Dr. Memory\bin\dynamorio\bin32\
create_process.exe":

This is a simple path error: you're inside the bin directory where there is no dynamorio subdirectory.  It is one level up.
Message has been deleted

nancygreen

unread,
Nov 4, 2016, 5:40:25 AM11/4/16
to Dr. Memory Users
Thanks, it works!

The init program:test with "-show_reachable -report_leak_max -1" option
      7 unique,     7 total,    550 byte(s) of leak(s)
      0 unique,     0 total,      0 byte(s) of possible leak(s)
    122 unique,   217 total, 142596 byte(s) of still-reachable allocation(s)

    total 46119(bytes) reported REACHABLE LEAK by results.txt

test with "-show_reachable -report_leak_max -1 -top_stats -dr_ops -early_inject -- ../dynamorio/bin64/create_process.exe  myapp"
      0 unique,     0 total,      0 byte(s) of leak(s)
      0 unique,     0 total,      0 byte(s) of possible leak(s)
     20 unique,    81 total,  16950 byte(s) of still-reachable allocation(s)

     total 13588(bytes) reported REACHABLE LEAK by results.txt
    
46119+16950=63069 < 142596 (I thought the reported leaked + early_inject reported leak = total reachable leak, but the gap is too much)

Adds my patch to release memory pool memory which will release 11164 bytes
test with "-show_reachable -report_leak_max -1" option
     16 unique,    16 total,   3030 byte(s) of leak(s)
      0 unique,     0 total,      0 byte(s) of possible leak(s)
     68 unique,   163 total, 128691 byte(s) of still-reachable allocation(s)

142596-128691=13905>11164   I don't known why Leak increate to 3030 bytes

It's really hard for me to understand why those numbers can't match, still some unknown numbers.





Reply all
Reply to author
Forward
0 new messages