Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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;


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: