Any reason to use SecureZeroMemory() instead of memset() or ZeroMemory() when security is not an issue? Any reason to use SecureZeroMemory() instead of memset() or ZeroMemory() when security is not an issue? windows windows

Any reason to use SecureZeroMemory() instead of memset() or ZeroMemory() when security is not an issue?


SecureZeroMemory is never optimized-away by a compiler. That is important if you need to worry about the contents of your memory to be cleaned, say if it contains very sensitive user info, e.g. banking software, passwords, etc. Obviously if there's no need for you to worry about such things, you can use any other way of cleaning memory buffers or not cleaning at all if it's not necessary.


It makes no sense to use SecureZeroMemory to initialize an icon info structure. It can only overwrite bytes on the stack frame that should have been securely erased elsewhere. That horse already escaped the barn. It doesn't even make sense to initialize it at all, the return value of GetIconInfo() tells you that it got initialized.

SecureZeroMemory() only makes sense after memory was filled with secure data.