Re: Last bogus commit from Stipe

"Alexander Malysh" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
no it just doesn't work as made Stipe and as you suggested. IIt just was  
typo in my example.
Just compile this code sniplet and you will see that your and Stipe  
changes are pointless:

---- snip -----
static void my_func(void *a)
{
	printf("a=%p", a);
	gw_free(a);
	printf("a=%p", a);
}

int main(int argc, char **argv)
{
	void *a = gw_malloc(10);
	my_func(a);
	if (a == NULL)
		printf("Andreas is right :)");
	else
		printf("Alex is right...");
	exit(0);
}
---- snip -----

P.S. I reverted Stipe's change...

Am 22.01.2007, 16:26 Uhr, schrieb Andreas Fink <[email protected]>:

>
> On 22.01.2007, at 15:48, Alexander Malysh wrote:
>
>> Hi Andreas,
>>
>> with your macro you will change nothing. Just example:
>>
>> 	a = gw_malloc(10)
>> 	some_func(a)
>> 	/* but here a points to some plase in memory but is not NULL */
>>
>> void some_func(void *a)
>> {
>> 	do something with a;
>> 	gw_malloc(a);

instead of gw_malloc(a) here should be gw_free(a)

>> 	/* ok a here is NULL */
>> }
>
>
> note it was done on free not malloc!
> It just makes sure the ptr is NULL after freeing it.
> because this is a MACRO and not a function call, the reference is put
> in by its name not as a copy of it.
>
> I presume that was the intention of stipe
>
>>
>> Am 22.01.2007, 12:42 Uhr, schrieb Andreas Fink <[email protected]>:
>>
>>> I would suggest the use of a macro of the following style instead:
>>>
>>> #define	gw_free(ptr)		{ if(ptr) gw_native_free(ptr);ptr=NULL; }
>>>
>>>
>>> On 22.01.2007, at 12:22, Paul Keogh wrote:
>>>
>>>>
>>>> IMHO, this feels bad.
>>>>
>>>> If the programmatic logic is correct, then the freed memory cannot
>>>> be accessed
>>>> after it is free.
>>>>
>>>>
>>>> -----Original Message-----
>>>> From: Alexander Malysh [mailto:[email protected]]
>>>> Sent: Mon 22/01/2007 11:12
>>>> To: [email protected]
>>>> Subject: Last bogus commit from Stipe
>>>>
>>>> Hi Stipe,
>>>>
>>>> your last commit:
>>>>
>>>> Index: gateway/gwlib/gwmem-native.c
>>>> diff -u gateway/gwlib/gwmem-native.c:1.10 gateway/gwlib/gwmem-
>>>> native.c:1.11
>>>> --- gateway/gwlib/gwmem-native.c:1.10   Sun Jan  7 23:52:56 2007
>>>> +++ gateway/gwlib/gwmem-native.c        Mon Jan 22 02:22:25 2007
>>>> @@ -108,6 +108,7 @@
>>>>   void gw_native_free(void *ptr)
>>>>   {
>>>>       free(ptr);
>>>> +    ptr = NULL;
>>>>   }
>>>>
>>>>
>>>> is bogus and unneeded because you just set ptr to NULL but not
>>>> pointer af
>>>> caller. So this commit does nothing to prevent situation you
>>>> described and
>>>> should be reverted.
>>>>
>>>> --
>>>> Thanks,
>>>> Alex
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>> 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
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>> --
>> Thanks,
>> Alex
>>
>>
>
>
>
> 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
>
>
>
>
>



-- 
Thanks,
Alex
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.