use of malloc

Thorsten Kukuk kukuk@suse.de
Mon Apr 24 23:11:00 GMT 2000


On Fri, Apr 21, Ulrich Drepper wrote:


> - make sure you free all the memory allocated in the error case.  This
>   might get ugly but, as in the NIS file I corrected, you can use goto
>   for this.  This is a legitemate use of goto.

Uli, please look at the ChangeLog file. You have removed similar free's
in other parts of the NIS code.


> - optimize the user of malloc/calloc.  Often a struct and its content
>   have to be allocated at the same time.  The easiest way if to do it
>   on two steps with two allocations.  But if the information has the
>   same lifetime this is a waste.  The malloc and especially the free
>   function is pretty slow.

This is not true for NIS. All NIS functions needs the most time waiting
for the network. You will not see your optiomization in any benchmark,
but it makes the code look more ugly.

And your new Code is wrong. You derefence NULL Pointer !!!!!
Please remove it complete and don't change code, which you don't
understand in such a way.
What do you think is xdr_free () good for ?

  Thorsten

-- 
Thorsten Kukuk       http://www.suse.de/~kukuk/       kukuk@suse.de
SuSE GmbH            Schanzaeckerstr. 10            90443 Nuernberg
Linux is like a Vorlon.  It is incredibly powerful, gives terse,
cryptic answers and has a lot of things going on in the background.


More information about the Libc-hacker mailing list