In C and C++, Freeing a NULL pointer will result in nothing done.
Still, I see people saying that memory corruption can occur if you “free memory twice”.
Is this true? What is going on under the hood when you free memory twice?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
So, after
freeing the first time, you should dop = NULL, so if (by any chance),free(p)is called again, nothing will happen.Here is why freeing memory twice is undefined: Why free crashes when called twice