Or You Could Simplify The Error-Recovery Paths
Or You Could Simplify The Error-Recovery Paths
Posted Dec 25, 2014 21:34 UTC (Thu) by cesarb (subscriber, #6266)In reply to: Or You Could Simplify The Error-Recovery Paths by ldo
Parent article: The "too small to fail" memory-allocation rule
> if (failure)
> break;
> } while (false);
Wouldn't it be simpler and more readable to use a goto instead of a pseudo-loop?
(The Linux kernel does use the "set pointers to NULL and on error free them if they are not NULL" paradigm, of course using a "goto error" instead of a pseudo-loop, but the error-recovery paths being discussed are not merely "freeing locally allocated memory"; they can also have things like "unlocking a mutex" or "updating the filesystem block allocation structures to mark as free the blocks which had been reserved for this task".)