handling cleanup attributes with a goto

Dan Carpenter <[email protected]> Wed, 3 Jun 2026 11:41:33 +0300
Newsgroups org.kernel.vger.linux-sparse
Message-ID <[email protected]>
If you have code like:

	for (i = 0; i < 10; i++) {
		struct foo *buf __free(kfree) = NULL;

		if (frob())
			goto one;

one:
		blah(); blah(); blah();

		if (frob())
			goto two;
	}

two:
	blah(); blah(); blah();

The goto one won't free the buf because the label is inside the block
but the goto two will because it's outside.

At first I thought I could get the scope that the label is in from
the stmt->goto_label->label_scope but that's scope where the goto
can be and not where the label is.  Is there a way to get the
information about the scope where the label is?

regards,
dan carpenter