Re: Last bogus commit from Stipe

Andreas Fink <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
its not perfect but better to have Octstr * being set to NULL then to  
be left.

Generally a free function for any type of object should be defined as  
passing a double pointer

like

MyOctstr * x;

x = NewAllocMyOctstr()
do_something(x);
FreeAllocMyOctstr(&x);

whereas

FreeAllocMyOctstr(**x)
{
	gw_free(*x)
	*x = NULL;
};

This is what I call defensive programming. Never the less, its too  
late to introduce that into gwlib with its many different object  
types except by some places where you can use a macro instead to put  
the variable to NULL after freeing that object type. It wont work for  
nested calls but it does work for objects of that type.


On 22.01.2007, at 19:46, Stipe Tolj wrote:

> Andreas Fink wrote:
>> depends on WHERE you do this macro
>> I often use it on ocstr_destroy by using O_DESTROY instead doing  
>> just  setting my octstr * to NULL after the call.
>
> yep, as far as the octstr_create() is in the same stack scope.
>
> If you pass the Octstr* pointer to several subsequent subcalls, and  
> down the lane you do gw_free(), then there is no use for it.
>
> Complexity is the callstack IMO.
>
> Stipe
>
> -------------------------------------------------------------------
> Kölner Landstrasse 419
> 40589 Düsseldorf, NRW, Germany
>
> tolj.org system architecture      Kannel Software Foundation (KSF)
> http://www.tolj.org/              http://www.kannel.org/
>
> mailto:st_{at}_tolj.org           mailto:stolj_{at}_kannel.org
> -------------------------------------------------------------------



Andreas Fink

Fink Consulting GmbH
Global Networks Schweiz AG
BebbiCell AG

---------------------------------------------------------------
Tel: +41-61-6666330 Fax: +41-61-6666331  Mobile: +41-79-2457333
Address: Clarastrasse 3, 4058 Basel, Switzerland
E-Mail:  [email protected]
www.finkconsulting.com www.global-networks.ch www.bebbicell.ch
---------------------------------------------------------------
ICQ: 8239353 MSN: [email protected] AIM: smsrelay Skype: andreasfink
Yahoo: finkconsulting SMS: +41792457333
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.