视觉泄漏探测器崩溃

时间:2010-07-03 05:03:54

标签: memory memory-leaks ogre3d visual-leak-detector

我正在使用Visual Leak Detector来检测程序中的内存泄漏。程序运行完毕后,我会通过 utility.cpp 中的以下代码触发断言。当Visual Leak Detector的标题从程序中排除时,程序将运行并退出而不会发生意外。

// 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?

我不确定为什么断言被触发。有没有人知道可以触发断言的场景?

由于

2 个答案:

答案 0 :(得分:1)

我正在使用ogre3d + vld,我得到同样的问题! 我用GetLastError()调试了错误代码: ERROR_PROC_NOT_FOUND,错误127:找不到指定的过程。

好处是,如果你注释掉断言并重新编译,它可以工作(用“new char [20]”测试), 但如果你忘记调用“删除Ogre :: Root :: getSingletonPtr();”它不会被发现:(

编辑:要向调试控制台报告断言,您可以使用:

        // 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?

结果将是:

============================================
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
============================================

答案 1 :(得分:1)

尝试使用不同的调试器来检查泄漏。我会使用deleaker