On Mon, Sep 07, 2026 at 11:54:41PM +0200, Oleg Nesterov wrote:
quoted
This might be my - admittedly shallow - understanding of scoped_guard,
but does scoped guard handle goto correctly?
Yes, it does,
quoted
and why it's generally discouraged to mix cleanup.h and goto.
Hmm, why? I didn't know...
one of the reasons to use cleanup.h it is to eliminate the "goto
for exit cleanup" mechanism in the first place (says so in the first
paragraph of cleanup.h).
Later in the header is explicit says don't mix:
* Lastly, given that the benefit of cleanup helpers is removal of
* "goto", and that the "goto" statement can jump between scopes, the
* expectation is that usage of "goto" and cleanup helpers is never
* mixed in the same function. I.e. for a given routine, convert all
* resources that need a "goto" cleanup to scope-based cleanup, or
* convert none of them.
This particular patch only does a partial conversion - so it's a
bit of an anti-pattern.
Reading up on scoped_guard a bit more it seems you're right it handles
the issue to jump-out, but i can see why cleanup.h says "don't do that"
because it's confusing to look at / hard to reason about.
~Gregory