Re: Freeing the contents of a union



Hey,

On Tue, 2003-02-11 at 08:06, ERDI Gergo wrote:
> Hi,
> 
> Suppose I have a union like this:
> 
> union Foo switch (long)
> {
>   case 0: long   num_val;
>   case 1: string str_val;
>   case 2: Object obj_val;
> };
> 
> 
> How do I overwrite its value without leaking? Calling Foo__freekids() can
> easily segfault because if, for example, _d is 0 and num_val is something
> like 5, Foo__freekids() will try to CORBA_free 0x05 as a string/object.

	I just glanced at ORBit_freekids_via_TypeCode_T and it seems to be
doing the right thing - it looks at the discriminator and figures out
how to free the value - in the case of _d == 0 it should do nothing ...
as I'm reading it anyway.

	_freekids isn't in the spec anyway so I think you're expected to do the
freeing yourself:

	switch (foo->_d) {
	case 0:
		break;
	case 1:
		CORBA_free (foo->_u.str_val);
		break;
	case 2:
		CORBA_Object_release (foo->_u.obj_val);
		break;
	}


	But, again - freekids *should* work ..

Good Luck,
Mark.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]