[Olsr-dev] Good use patterns of "goto" - or not? (was Re: httpinfo IPv6 patch)
Roar Bjørgum Rotvik
(spam-protected)
Tue Nov 18 16:54:38 CET 2008
Alina Friedrichsen wrote:
> Hi Bernd!
>> [...]
>> freexyz_and_out:
>> free(z);
>> freexy_and_out:
>> free(y);
>> freex_and_out:
>> free(x);
>> return rv;
>> }
> I write often the following:
> [...]
> failure:
> if(x != NULL) free(x);
> if(y != NULL) free(y);
> if(z != NULL) free(z);
> return false;
> }
I also likes this approach a lot better than copying the error handing in every code
branch. The goto call in it self is not evil or dangerous, it all depend on how it is used.
But I don't think a check for NULL before calling free() is needed, most operating system
as I know of handles a NULL pointer just fine (please correct me if you know of any system
that does not).
From Linux "man 3 free":
"If ptr is NULL, no operation is performed."
From MS MSDN (windows):
"If memblock is NULL, the pointer is ignored and free immediately returns."
--
Roar Bjørgum Rotvik
More information about the Olsr-dev
mailing list