Practice mode C Language

What does the C standard say happens if free() is called twice on the same pointer without reallocating it?

Correct answer B. The behaviour is undefined

Explanation

After the first free, the pointer no longer refers to an allocated block, and passing it to free again is undefined behaviour. It may corrupt the allocator's internal data and is a known security weakness. free(NULL) is the safe exception, which is why setting a pointer to NULL immediately after freeing it guards against double frees.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.