C6332
警告 C6332: 無效的參數: 不允許將零做為 dwFreeType 參數傳遞至 <function>。這樣就會造成這個呼叫的失敗
這項警告表示傳遞至 VirtualFree 或 VirtualFreeEx 的參數無效。VirtualFree 和 VirtualFreeEx 都會拒絕值為零的 dwFreeType 參數。dwFreeType 參數可以是 MEM_DECOMMIT 或 MEM_RELEASE。不過,值 MEM_DECOMMIT 和 MEM_RELEASE 不能一起用於相同的呼叫中。此外,請確保不會忽略 VirtualFree 函式的傳回值。
範例
因為傳遞至 VirtualFree 函式的參數無效,所以下列程式碼會產生這項警告:
#include <windows.h>
#define PAGELIMIT 80
DWORD dwPages = 0; // count of pages
DWORD dwPageSize; // page size
VOID f( VOID )
{
LPVOID lpvBase; // base address of the test memory
BOOL bSuccess;
SYSTEM_INFO sSysInfo; // system information
GetSystemInfo( &sSysInfo );
dwPageSize = sSysInfo.dwPageSize;
// Reserve pages in the process's virtual address space
lpvBase = VirtualAlloc(
NULL, // system selects address
PAGELIMIT*dwPageSize, // size of allocation
MEM_RESERVE,
PAGE_NOACCESS );
if (lpvBase)
{
// code to access memory
}
else
{
return;
}
bSuccess = VirtualFree( lpvBase, 0, 0 );
// code ...
}
若要更正這項警告,請修改 VirtualFree 函式的呼叫,如下列程式碼所示:
#include <windows.h>
#define PAGELIMIT 80
DWORD dwPages = 0; // count of pages
DWORD dwPageSize; // page size
VOID f( VOID )
{
LPVOID lpvBase; // base address of the test memory
BOOL bSuccess;
SYSTEM_INFO sSysInfo; // system information
GetSystemInfo( &sSysInfo );
dwPageSize = sSysInfo.dwPageSize;
// Reserve pages in the process's virtual address space
lpvBase = VirtualAlloc(
NULL, // system selects address
PAGELIMIT*dwPageSize, // size of allocation
MEM_RESERVE,
PAGE_NOACCESS );
if (lpvBase)
{
// code to access memory
}
else
{
return;
}
bSuccess = VirtualFree( lpvBase, 0, MEM_RELEASE );
// code ...
}