Comment
Comment by ffffjfjjfj
This gives a false sense of security, since the most common use-after-free bugs are if you kept a pointer around. Your method doesn't stop things like this:
Obviously its trivial in an example like this, but when p2 leaves the lexical scope then there's a problem.