views:

48

answers:

1

Hi,

I am using Visual Leak Detector to detect memory leaks in my program. When the program has finished running, I get an assertion triggered by the following code in utility.cpp. When Visual Leak Detector's header is excluded from the program, the program runs and exits without incident.

// Get the *real* address of the import. If we find this address in the IAT,
// then we've found that the module does import the named import.
import = GetProcAddress(exportmodule, importname);
assert(import != NULL); // Perhaps the named export module does not actually export the named import?

I am not sure why the assert is being triggered. Does anybody have an idea in what scenarios the assertion can be triggered?

Thanks

+1  A: 

Hi! I am using ogre3d + vld and I get same issue! I debugged the error code with GetLastError(): ERROR_PROC_NOT_FOUND, error 127: The specified procedure could not be found.

The good thing is, that it works(tested with "new char[20]") if you comment out that assertation and recompile, but if you forget to call "delete Ogre::Root::getSingletonPtr();" it wont be detected :(

Edit: To report assertations to the debug console you can use this:

        // Get the *real* address of the import.
    import = GetProcAddress(exportmodule, importname);

    if(import == NULL){
        DWORD err=GetLastError(); 
        WCHAR buff[2048];
        wcsncpy_s(buff, 2048, L"\n============================================\nImport name: ", _TRUNCATE);
        int i=wcslen(buff);
        int n=0;
        //cast to unicode
        while(importname[n]){
            buff[i++]=importname[n++];
        }
        buff[i]=0;
        wcsncat_s(buff, 2048, L"\nExport module: ", _TRUNCATE);
        i=wcslen(buff);
        GetModuleFileName(exportmodule,&buff[i],2048-i);
        wcsncat_s(buff, 2048, L"\nError code: ", _TRUNCATE);
        i=wcslen(buff);
        _itow_s(err,&buff[i],2048-i,10);
        wcsncat_s(buff, 2048, L"\n============================================\n", _TRUNCATE);
        report(buff);
    }
    //assert(import != NULL); // Perhaps the named export module does not actually export the named import?

Result will be:

============================================
Import name: CoGetMalloc
Export module: C:\data\projects\Avenon\trunk\source\..\build\Avenon_d.exe
Error code: 127
============================================

============================================
Import name: CoTaskMemAlloc
Export module: C:\data\projects\Avenon\trunk\source\..\build\Avenon_d.exe
Error code: 127
============================================

============================================
Import name: CoTaskMemRealloc
Export module: C:\data\projects\Avenon\trunk\source\..\build\Avenon_d.exe
Error code: 127
============================================
Sajty
Hi Sajty, thanks for the reply. You are right, it does work but ogre's pointers fail to get detected if they are leaked. Still it is better than the standard leak detector. Thanks again!
Samaursa
UPDATE: It randomly stopped working for me again. I have compiled against release and debug and checked with both (commented out the asserts) and the same problem persists. The worst part is that a window shows for a split second before it disappears so I cannot know what happened. My debug output shows: First-chance exception at 0x7589b727 in ProjectName.exe: Microsoft C++ exception: OIS::Exception at memory location 0x003cf2d4.. =( ... very sad because when it works, it works wonders
Samaursa
Hi! I have used it a lot and I used OIS keyboard and mouse too, and no crash. Try it without vld for a time, if it throws exceptions too, then its not vld. I use dbghelp from windows7 system32 folder which is v6.1.7600.16385
Sajty