2

My windows program consists of

  • a C++(MFC) console application my.exe, which issues _CrtSetDbgFlag to see memory leaks on exit.

  • a C++(non-MFC) my.dll. This dll calls a 3rd party library (Oracle's OCCI C++ library).

my.exe has a deliberate leak in its main() function : new char[333];

When the program exits I see these leaks:-

Detected memory leaks! Dumping objects -> ...myExe.cpp(62) : {384} normal block at 0x0087C4B0, 333 bytes long.

However, if I call certain functions in the 3rd party library then no leaks are reported on exit. That is, I can call some occi functions from my dll, but as soon as I call the occi function to actually connect to a database (which seem to work well), then all my leak reporting disappears as if there are no leaks.

I suspect this is happening because although I am using the correct version of oracle's occi dll, this uses oracle's lower level oci.dll, which appears to use an older version of the MSVC runtime. Dependency walker shows:

MY.EXE
    MSVCR100D.DLL
    MY.DLL
        MSVCR100D.DLL
        ORAOCCI11D.DLL
            MSVCR100D.DLL
            OCI.DLL
                MSVCR80.DLL

Thanks for any comments.

Philip Beck
  • 375
  • 2
  • 10
  • 1
    I presume you have something like `::_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );` at the beginning of your program workflow. I suspect the cause of your problem is: one of these libraries is calling `_CrtSetDbgFlag` to **UNSET** memory dumping you had **SET** before. If possible put a breakpoint on `_CrtSetDbgFlag` to see who is calling it. – sergiol Apr 25 '17 at 00:18
  • And BTW, I recommend you to use something more advanced to detect memory leaks like Visual Leak Detector – sergiol Apr 25 '17 at 01:20
  • 1
    Thanks for those suggestions. I tried both. 1. A breakpoint in _CrtSetDbgFlag(). After my initial call, it hits this breakpoint about 30 times during my minimal console application, but not when I call the 3rd party library function that causes the problem. So I don't think that function is not causing this to UNSET. – Philip Beck Apr 25 '17 at 16:13
  • 1
    2. I tried Visual Leak Detector and it looks quite good. As well as my intentional leaks, it spotted 2 others that _CrtSetDbgFlag() didn't. However, when I called the 3rd party library function that causes the problem, the result was exactly the same. My program exits with zero leaks reported. In fact the message **Visual Leak Detector is now exiting**, is not displayed at all. – Philip Beck Apr 25 '17 at 16:33
  • 1
    I think it's my fault in that my top level Oracle dll (occi.dll) doesn't match the installed version of the lower level Oracle dll (oci.dll). I think when I sort this, they will all use MSVCR100. Thanks for your help. – Philip Beck Apr 25 '17 at 16:34

0 Answers0