[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: (ITS#4483) Confusion in freeing BerElement in abnormal conditions



On Sat, 2006-04-08 at 19:25 +0200, Hallvard B Furuseth wrote:

> It looks to be that you just described that the ber_flush() function has
> a somewhat cumbersome interface.  Would it be useful to make the freeit
> parameter should an enum?  Values:
> { 0 => don't free,
>   some unlikely magic number => free unless error,
>   1 => free (the "official" name & value for freeing),
>   default => also free, for backwards compat }

Ehm, actually I didn't even realize ber_flush() had a man page.  In any
case, I find that man page ambiguous much like the function interface.

What if I add a set of macros like

LBER_FLUSH_FREE_NEVER		(0x0)
LBER_FLUSH_FREE_ON_SUCCESS	(0x1)
LBER_FLUSH_FREE_ON_ERROR	(0x2)
LBER_FLUSH_FREE_ALWAYS		(LBER_FLUSH_FREE_ON_SUCCESS|LBER_FLUSH_FREE_ON_ERROR)

ans use them consistently?  Code using 0 and 1 will use the default
behavior (no matter if aware or not of its potential side effects) and
behave as usual; fancy code that uses anything but 1 for "freeit" will
behave unpredictably.

Another option is to introduce a ber_flush2() function that uses the new
interface, and make

int
ber_flush( Sockbuf *sb, BerElement *ber, int freeit )
{
	return ber_flush2( sb, ber,
		freeit ? LBER_FLUSH_FREE_ON_SUCCESS
			: LBER_FLUSH_FREE_NEVER );
}

I think I'll go this second way.

p.




Ing. Pierangelo Masarati
Responsabile Open Solution
OpenLDAP Core Team

SysNet s.n.c.
Via Dossi, 8 - 27100 Pavia - ITALIA
http://www.sys-net.it
------------------------------------------
Office:   +39.02.23998309          
Mobile:   +39.333.4963172
Email:    pierangelo.masarati@sys-net.it
------------------------------------------