News for hackers. Stuff that matters.
Re:C Programming Guidelines by userbinator on Wednesday September 02, 2015 @01:39AM (#10157604)
That's a very common pattern in Linux kernel code, where there's also nested cleanups, and is one of the most suitable use-cases for a goto.

Although in your example, if the code really was doing only that much, I'd recognise the ||/&& "ladder" structure and write it like this instead:

    if(!(p=a()) && (q=b()) && (r=c()))) {
     free(p);
     free(q);
     free(r);
    }
Re:C Programming Guidelines by asveikau on Wednesday September 02, 2015 @02:05AM (#10157663)
The code example was meant to illustrate the pattern while still being something that's semi-reasonable to write in a web form. Obviously in real life you'd want to do something with p, q, and r, which could make the chain of ANDs [not a pattern I am averse to in general] a bit more clumsy. YMMV.

I guess the other point I am trying to make is that success and failure can hit mostly the same code. Your snippet only checks for failure.