验证Authenticode签名的可执行文件时内存泄漏?

我正在使用WinVerifyTrust来验证某些Windows可执行文件的有效性,使用以下函数,在
_tmain
的循环中调用:
int signature_is_valid(const wchar_t *filepath) {
    GUID guid = WINTRUST_ACTION_GENERIC_VERIFY_V2;
    WINTRUST_FILE_INFO file_info = { 0 };
    WINTRUST_DATA wd;

    file_info.cbStruct = sizeof(file_info);
    file_info.pcwszFilePath = filepath;
    file_info.hFile = NULL;
    file_info.pgKnownSubject = NULL;

    ZeroMemory(&wd, sizeof(wd));
    wd.cbStruct = sizeof(wd);
    wd.dwUIChoice = WTD_UI_NONE;
    wd.fdwRevocationChecks = WTD_REVOCATION_CHECK_NONE;
    wd.dwUnionChoice = WTD_CHOICE_FILE;
    wd.dwStateAction = 0;
    wd.pFile = &file_info;
    wd.dwProvFlags = WTD_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT | WTD_CACHE_ONLY_URL_RETRIEVAL;

    return 0 == WinVerifyTrust(NULL, &guid, &wd);
}
但是,随着每个循环内存不断增长,这是内存泄漏的可靠信号。 我对
API
的理解是否存在问题,或者
WinVerifyTrust
函数是否实际泄漏?我在
Windows XP Professional SP3
系统上测试这个。 编辑: 以下是
umdh
的一些输出:
+   16812 (  16992 -    180)    472 allocs BackTraceAD1
+     467 (    472 -      5) BackTraceAD1 allocations

 ntdll!RtlDebugAllocateHeap+000000E1
 ntdll!RtlAllocateHeapSlowly+00000044
 ntdll!RtlAllocateHeap+00000E64
 kernel32!LocalAlloc+00000058
 CRYPT32!operator new+00000011
 CRYPT32!I_CryptCreateLruEntry+00000011
 CRYPT32!CreateAuthRootAutoUpdateMatchCaches+00000107
 CRYPT32!CCertChainEngine::FindAuthRootAutoUpdateMatchingCtlEntries+0000004D
 CRYPT32!CChainPathObject::GetAuthRootAutoUpdateUrlStore+000000C9
 CRYPT32!CChainPathObject::CChainPathObject+0000030E
 CRYPT32!ChainCreatePathObject+00000050
 CRYPT32!CCertIssuerList::AddIssuer+0000006A
 CRYPT32!CChainPathObject::FindAndAddIssuersFromStoreByMatchType+00000182
 CRYPT32!CChainPathObject::FindAndAddIssuersByMatchType+00000096
 CRYPT32!CChainPathObject::FindAndAddIssuers+00000023
 CRYPT32!CChainPathObject::CChainPathObject+000001F9
 CRYPT32!ChainCreatePathObject+00000050
 CRYPT32!CCertIssuerList::AddIssuer+0000006A
 CRYPT32!CChainPathObject::FindAndAddIssuersFromCacheByMatchType+00000084
 CRYPT32!CChainPathObject::FindAndAddIssuersByMatchType+00000023
 CRYPT32!CChainPathObject::FindAndAddIssuers+00000063
 CRYPT32!CChainPathObject::CChainPathObject+000001F9
 CRYPT32!ChainCreatePathObject+00000050
 CRYPT32!CCertChainEngine::CreateChainContextFromPathGraph+0000019E
 CRYPT32!CCertChainEngine::GetChainContext+00000044
 CRYPT32!CertGetCertificateChain+00000060
 WINTRUST!_WalkChain+0000019C
 WINTRUST!WintrustCertificateTrust+000000B7
 WINTRUST!_VerifyTrust+00000144
 WINTRUST!WinVerifyTrust+0000004E
 SigTest!signature_is_valid+000000DD 

+   10984 (  10984 -      0)      2 allocs BackTraceBB3
+       2 (      2 -      0) BackTraceBB3 allocations

 ntdll!RtlDebugAllocateHeap+000000E1
 ntdll!RtlAllocateHeapSlowly+00000044
 ntdll!RtlAllocateHeap+00000E64
 kernel32!LocalAlloc+00000058
 CRYPT32!PkiDefaultCryptAlloc+00000011
 CRYPT32!CertFindCertificateInCRL+00000051
 cryptnet!MicrosoftCertDllVerifyRevocation+00000250
 CRYPT32!I_CryptRemainingMilliseconds+0000021B
 CRYPT32!CertVerifyRevocation+000000B7
 CRYPT32!CChainPathObject::CalculateRevocationStatus+000001F2
 CRYPT32!CChainPathObject::CalculateAdditionalStatus+00000147
 CRYPT32!CCertChainEngine::CreateChainContextFromPathGraph+00000227
 CRYPT32!CCertChainEngine::GetChainContext+00000044
 CRYPT32!CertGetCertificateChain+00000060
 WINTRUST!_WalkChain+0000019C
 WINTRUST!WintrustCertificateTrust+000000B7
 WINTRUST!_VerifyTrust+00000144
 WINTRUST!WinVerifyTrust+0000004E
 SigTest!signature_is_valid+000000DD
 SigTest!wmain+00000073
 SigTest!__tmainCRTStartup+000001A8
 SigTest!wmainCRTStartup+0000000F
 kernel32!BaseProcessStart+00000023
在我看来,
CRYPT32
功能是泄漏的......或者我错过了什么。 EDIT2 这是几千个循环的内存演变:     
已邀请:
我没有看到此API泄漏的任何信息。也许这只是在这个过程中的堆碎片? 您可以使用umdh确认这一点,以便在时间X和X + delta处获取进程的快照,然后分析这些时间的比较堆使用情况。确保所有符号都可用,这是最有帮助的。     
(编辑:看看新图表,我错了。) 根据callstack中的“I_CryptCreateLruEntry”,我的猜测是这不是内存泄漏;它只是有限的API缓存数据。即它不会无限增长。 该名称中的LRU表明它正在将其在最近最少使用的缓存中获得的证书存储起来,以便加速可能涉及相同证书的后续操作。 如果你在循环中运行代码并发现它使用几兆字节并且在多次迭代后仍然在增长,那么可能存在泄漏,或者配置非常糟糕的缓存算法,但是否则我会说你可能没有什么可担心的。     
根据WINDUST_DATA的MSDN文档,Windows XP或Windows 2000不支持WTD_CACHE_ONLY_URL_RETRIEVAL。我怀疑这与明显的泄漏有什么关系,但认为可能值得指出。     
是。如果你有一个足够低版本的crypt32.dll文件,那么会有一个非常烦人的内存泄漏。 看到 http://social.technet.microsoft.com/Forums/en-US/itproxpsp/thread/c11530e8-56e2-4bb3-a887-f7809e644861 并安装修补程序KB2641690以进行修复     

要回复问题请先登录注册