Hi,
I just saw something kind of scary in some C++ code I'm fixing. The code allocates memory with VirtualAlloc(), then then later deletes it using free().
Is that safe?
Should I change it to VirtualFree() instead?
Printable View
Hi,
I just saw something kind of scary in some C++ code I'm fixing. The code allocates memory with VirtualAlloc(), then then later deletes it using free().
Is that safe?
Should I change it to VirtualFree() instead?
It is almost certainly not at all safe - in fact I'd be surprised if it actually works OK in the first instance.
And yes, you should use free.
If the original VirtualAlloc is a plain memory allocation with no "funny" parameters, it may not crash or be terribly bad in any other way, but you certainly wouldn't want any memory with "special" settings to end up in the heap.
--
Mats
Thanks, I changed them to use VirtualFree().