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

Discussion

As soon as a pointer variable is freed, its value 

  • A.is set to null
  • B.becomes unpredictable
  • C.is set to 1
  • D.remains the same

Answer: D

Correct answer: remains the same

free releases the storage but does nothing to the pointer, which is passed by value. Its bits are unchanged, so it still holds the address of memory that no longer belongs to the program - a dangling pointer.

This is exactly what makes use-after-free so dangerous: the pointer looks valid, may still appear to work while the freed block is untouched, and fails unpredictably once the allocator reuses it. The conventional discipline is to set the pointer to NULL immediately after freeing, so that misuse fails loudly.

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

Post your comment

Please log in or register to post a comment.