Part of the problem seems to be that the "goto cleanup" style requires a single exit from the function, so you have to be sure to set the correct return value before reaching that single exit point.
If you have destructors (or cleanup attributes, or whatever) that run automatically on exit from the function you just "return 0;" immediately as soon as you like, instead of setting a value, then hoping it doesn't get changed again before the end of the function, then running the cleanup code, and then returning that value.
Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds