Skip to contentSkip to conversation

handling cleanup attributes with a goto

DISCUSSION Dan Carpenter 1 participant 1 message Jun 3 Sparse checker

lore
Share & tools
lore
#0 lore raw

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