clean exit - suggestions?

From: lallous (lallous_at_lgwm.org)
Date: 01/09/04


Date: Fri, 9 Jan 2004 14:19:42 +0200

Hello,

I have a function like:

void fnc() {
char *mem1, *mem2, *mem3, *mem4;
// lots of code...
// mem1, 2, 3, 4 got allocated
// lots of code and condition checks
if (condition_failed)
{
  // blah blah
  // free mem1, mem2, mem3, mem4
  return;
}

if (condition2_failed)
{
  // blah blah
  // free mem1, mem2, ...
 return;
}

// here the end of routine (clean exit code):
// free mem1, mem2, mem3, mem4
}

Usually, I would use compiler specific solution by putting most of the code
in __try() and the clean exit code in _finally() block then to reach the
clean exit code I would invoke __leave.

Or use lables and then goto clean_exit

Any better way, other than goto or compiler specific solution?

--
Elias