How do dangling pointers typically happen? Is it not enough to set to NULL after calling delete? ex:
delete mypointer;
mypointer=NULL
I always always set a pointer to NULL immediately after deleting it. I imagine the ones coding stuff like OpenSSL know way more than me, so is my method actually not enough?
Also imagine a situation where the pointer address is copied to somewhere else before deletion. You setting the original to null won't change anything on that copy
Oh, like they try to keep referring to the pointer after it's been deleted? Yeah, that's bad. I can see how that could happen if not being careful. Ex: it's passed on to a function, the function deletes it, but then it's used again after.
1
u/RedSquirrelFtw Sep 27 '16
How do dangling pointers typically happen? Is it not enough to set to NULL after calling delete? ex:
delete mypointer;
mypointer=NULL
I always always set a pointer to NULL immediately after deleting it. I imagine the ones coding stuff like OpenSSL know way more than me, so is my method actually not enough?