3 ms·
If you are constructing arguments in order, you can destroy them in the reverse order at the exit and this lets you cleanly handle a failure in the middle of al
by dllthomas 13y ago
If you are constructing arguments in order, you can destroy them in the reverse order at the exit and this lets you cleanly handle a failure in the middle of allocations:
thing1 = allocate_thing1();
if(!thing1) goto cleanup1;
thing2 = allocate_thing2();
if(!thing2) goto cleanup2;
...
cleanup3: deallocate_thing2(thing2);
cleanup2: deallocate_thing1(thing1);
cleanup1: return;