1

我正在使用 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?

我不确定为什么要触发断言。有人知道在什么情况下可以触发断言吗?

谢谢

4

2 回答 2

1

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

于 2011-11-21T19:32:57.017 回答
1

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

好消息是,如果您注释掉该断言并重新编译,它可以工作(使用“new char[20]”测试),但如果您忘记调用“delete 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?

结果将是:

============================================
导入名称:CoGetMalloc
导出模块:C:\data\projects\Avenon\trunk\source\..\build\Avenon_d.exe
错误代码:127
============================================

============================================
导入名称:CoTaskMemAlloc
导出模块:C:\data\projects\Avenon\trunk\source\..\build\Avenon_d.exe
错误代码:127
============================================

============================================
导入名称:CoTaskMemRealloc
导出模块:C:\data\projects\Avenon\trunk\source\..\build\Avenon_d.exe
错误代码:127
============================================
于 2010-08-09T19:00:07.257 回答