Machine-translated by Google. Questions are authored in English.
Top

Discussion

Calling free() twice on the same pointer results in ________.

  • A.the memory being returned twice, which is harmless
  • B.undefined behaviour
  • C.a compile-time error
  • D.the pointer being set to NULL automatically

Answer: D

Correct answer: undefined behaviour

A double free corrupts the allocator’s internal bookkeeping and its consequences are undefined, ranging from a silent fault to an exploitable crash. Assigning NULL to the pointer after the first free() makes any second call harmless.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.