[Asterisk-Dev] calloc vs malloc ?

Russell Bryant russell at digium.com
Sat Dec 24 15:09:03 MST 2005


On Dec 24, 2005, at 1:16 PM, Luigi Rizzo wrote:
> Apart from making the code more robust (because a malloc
> without a comment epxlaining why clearing is not necessary
> would immediately trigger the developer's attention),
> by using calloc() we would also give
> the allocator a chance to hand us clean pages without
> redoing the clearing ourselves.

I agree.  As a matter of fact, I think we should consider adding a  
statement in the coding guidelines document that says to always use  
calloc, unless un-initialized memory is acceptable.  Furthermore, we  
should require that a call to malloc without a corresponding memset  
have a comment noting why this is the case.

I was planning on going through and cleaning most of this up once the  
patch discussed in bug 4996 got accepted.

-- 
Russell Bryant





More information about the asterisk-dev mailing list