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);
  1. What does delete do in C ++ ?
  2. If not, then delete () What is the best way to do this in C ++ , div>

    1. delete (), it Automatically in C ++?

      no

      1. 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

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -