[asterisk-dev] [Code Review]: ensure that ast_string_field_pool base + used is always aligned
Terry Wilson
reviewboard at asterisk.org
Tue Nov 1 09:57:43 CDT 2011
> On Oct. 31, 2011, 12:34 p.m., mjordan wrote:
> > /branches/1.8/main/utils.c, line 1548
> > <https://reviewboard.asterisk.org/r/1549/diff/2/?file=21505#file21505line1548>
> >
> > This actually goes against the recommendations in the coding guidelines (2.17.3) - is there a specific reason to not use ast_calloc?
>
> David Vossel wrote:
> The memset after the malloc is for a smaller amount of memory than the entire allocation. The change appears safe, but I question why we'd even care about this optimization when it adds more complexity.
>
> wdoekes wrote:
> This isn't an increase in complexity, this is a fix. The original author should never have used calloc here. This is a very common pattern.
>
> I don't see how you could not care about the overhead of hundreds of bytes getting nulled for nothing when only a handful (struct ast_string_field_pool) should get nulled. Especially in core functions that were created to reduce load (individual string field mallocs) in the first place.
More information about the asterisk-dev
mailing list