News for hackers. Stuff that matters.
Re:Defensive Programming by ffffjfjjfj on Wednesday December 23, 2020 @03:07PM (#25521590)
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:

    void *p1, *p2;
    malloc(100, &p1);
    p2 = p1;
    ...
    free(&p1);
    *p2; // oops!
Obviously its trivial in an example like this, but when p2 leaves the lexical scope then there's a problem.
Re:Defensive Programming by btrask on Thursday December 24, 2020 @04:16AM (#25526115)
If you are transferring ownership, you would do

    p2 = p1; p1 = NULL;
However if you are intentionally doing multiple ownership, then yes you can still have problems.