PREfast Warning 249 (Windows CE 5.0)
249 - Calling <kernel function> without the MEM_RELEASE flag frees memory but not the address descriptors (VADs).
Consequence: Results in address space leaks.This warning is specific to Windows NT kernel-mode code.
This message warns that you must use MEM_RELEASE with NtFreeVirtualMemory to undo reserve memory that was reserved or committed using NtAllocateVirtualMemory.
NtAllocateVirtualMemory can reserve or commit memory. A commit of memory also reserves it. MEM_DECOMMIT undoes the commit, but not the reserve. MEM_RELEASE undoes the reserve.
NtFreeVirtualMemory behaves similarly to the Win32 function VirtualFree. For VirtualFree, if a page is decommitted but not released, its state changes to reserved. To completely release committed memory, it must be decommitted and released.
It is not necessary for the decommit and release to happen as independent steps. Releasing committed memory decommits the pages as well.
Example
Defective Source
ZwFreeVirtualMemory(0,
NULL,
0,
MEM_DECOMMIT);
ZwFreeVirtualMemory(0,
NULL,
0,
MEM_RELEASE);
Corrected Source
ZwFreeVirtualMemory(0,
NULL,
0,
MEM_RELEASE);
Send Feedback on this topic to the authors