[Asterisk-Dev] calloc vs malloc ?

Tilghman Lesher tilghman at mail.jeffandtilghman.com
Sat Dec 24 13:18:38 MST 2005


On Saturday 24 December 2005 12:16, Luigi Rizzo wrote:
> any reason why the sequences
>
> 	foo = malloc(sizeof(*foo));
> 	if (!foo) { /* error handling */ }
> 	memset(foo, 0, sizeof(*foo));
>
> are not implemented with proper calloc calls ?
>
> 	foo = calloc(1, sizeof(*foo));
> 	if (!foo) { /* error handling */ }
>
> 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.

It's already being discussed:
http://bugs.digium.com/view.php?id=4996

-- 
Tilghman



More information about the asterisk-dev mailing list