Partilhar via


C6333

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

warning C6333: Invalid parameter: passing MEM_RELEASE and a non-zero dwSize parameter to <function> is not allowed. This results in the failure of this call

This warning indicates an invalid parameter is being passed to VirtualFree or VirtualFreeEx. Both of these functions reject a dwFreeType of MEM_RELEASE with a non-zero value of dwSize. When passing MEM_RELEASE, the dwSize parameter must be zero. Also, make sure that the return value of this function is not ignored.

Example

The following sample code generates this warning:

#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, PAGELIMIT * dwPageSize, MEM_RELEASE);   
  //code...  
}  

To correct this warning, use the following sample code:

#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 );  
  
  //  VirtualFree(lpvBase, PAGELIMIT * dwPageSize, MEM_DECOMMIT);   
  // code...  
}  

You can also use VirtualFree(lpvBase, PAGELIMIT * dwPageSize, MEM_DECOMMIT); call to decommit pages, and later release them using MEM_RELEASE flag.

See Also

VirtualAlloc Method
VirtualFree Method