Better way for memory sanitization in C++ to void data leakage? -
While working in "C", I am using hygiene techniques to avoid data leakages directed by CITT:
memset (mem_name, '\ 0', mem_size); - What does
delete do in C ++ ? - If not, then
delete () What is the best way to do this in C ++ , div>
- delete (), it Automatically in C ++?
no
- If not, what is the better way to do it in C ++ using the delete ()?
In general it would be wrong in C ++:
foo * p = new fu (); Memeset (p, 0, saiff (fo)); Remove p; The problem is that the delete p will call the destroyer of the class, and if the destroyer is non-trivial then he may need to reach members of class Free related resources, but those members have been overwritten by memset . The equivalent destructor must explicitly invite, call , then use delete operator to clear the memory : foo * p = new Foo (); P-> ~ Foo (); Memeset (p, 0, saiff (fo)); :: Remove operator (P); But the compiler is allowed to optimize the memset, if it can see that no one uses the memory again, so the CERT Advice is very much Not good.
Comments
Post a Comment