Compartir a través de


Advertencia C6333

Parámetro no válido: no se permite pasar MEM_RELEASE y un parámetro dwSize distinto de cero a "function_name". Esto provocará un error en la llamada

Comentarios

Y VirtualFree rechazan un dwFreeType de MEM_RELEASE con un valor distinto de cero de dwSize.VirtualFreeEx Cuando MEM_RELEASE se pasa, el dwSize parámetro debe ser cero.

Nombre del análisis de código: VIRTUALFREEINVALIDPARAM3

Ejemplo

El siguiente ejemplo de código genera esta advertencia:

#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...
}

Para corregir esta advertencia, asegúrese de que el valor de dwSize es 0 en la llamada a 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);

    //  VirtualFree(lpvBase, PAGELIMIT * dwPageSize, MEM_DECOMMIT);
    // code...
}

También puede usar VirtualFree(lpvBase, PAGELIMIT * dwPageSize, MEM_DECOMMIT); la llamada para descommitar páginas y publicarlas posteriormente mediante MEM_RELEASE la marca .

Consulte también