Ethereal-dev: Re: [Ethereal-dev] CLEANUP_PUSH etc ...

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <gharris@xxxxxxxxx>
Date: Fri, 15 Mar 2002 11:40:29 -0800
On Sat, Mar 16, 2002 at 05:56:15AM +1030, Richard Sharpe wrote:
> It seems to me that CLEANUP_PUSH and CLEANUP_CALL_AND_POP should surround 
> code that is allocating memory dynamically, and serves to prevent/reduce 
> mem leaks when you take an exception due to trying to access memory in a 
> tvb beyond the end.
> 
> Is this the case?

Yes.

Any code that

	1) allocates memory that it frees later

and

	2) makes, between the allocation and the free, calls that might
	   throw an exception

should use "CLEANUP_PUSH()" after the allocation but before the calls
that might throw an exception, and should use "CLEANUP_CALL_AND_POP()"
to do the freeing.