[asterisk-dev] [Code Review] 2832: Fix incorrect usages of ast_realloc().

rmudgett reviewboard at asterisk.org
Fri Sep 6 20:04:53 CDT 2013



> On Sept. 6, 2013, 10:56 p.m., wdoekes wrote:
> > I wonder if an ast_realloc_or_free() wouldn't have been cleaner though.
> > 
> > void *ast_realloc_or_free(void *ptr, size_t size) {
> >   void *new = ast_realloc(ptr, size);
> >   if (!new) {
> >     free(ptr);
> >     return NULL;
> >   }
> >   return new;
> > }

That kind of routine would only work if ptr is just an allocated buffer.  Is many cases that buffer is an array of pointers to allocated strings.  Simply freeing that buffer would then leave any allocated strings orphaned.


- rmudgett


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/2832/#review9632
-----------------------------------------------------------


On Sept. 6, 2013, 10:36 p.m., rmudgett wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/2832/
> -----------------------------------------------------------
> 
> (Updated Sept. 6, 2013, 10:36 p.m.)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Repository: Asterisk
> 
> 
> Description
> -------
> 
> There are several locations in the code base where this is done:
> buf = ast_realloc(buf, new_size);
> 
> This is going to leak the original buf contents if the realloc fails.
> 
> Several of these incorrect usages should apply to v1.8 and v11.
> 
> 
> Diffs
> -----
> 
>   /branches/12/funcs/func_dialgroup.c 398615 
>   /branches/12/main/asterisk.c 398615 
>   /branches/12/main/cli.c 398615 
>   /branches/12/main/event.c 398615 
>   /branches/12/main/heap.c 398615 
>   /branches/12/main/indications.c 398615 
>   /branches/12/main/xmldoc.c 398615 
>   /branches/12/res/res_musiconhold.c 398615 
>   /branches/12/res/res_pjsip/pjsip_configuration.c 398615 
> 
> Diff: https://reviewboard.asterisk.org/r/2832/diff/
> 
> 
> Testing
> -------
> 
> Mostly compiled the code and code inspection.
> 
> * The CLI tab completion still works.
> * MOH still plays.
> * Online XML documentation still shows application syntax.
> 
> 
> Thanks,
> 
> rmudgett
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20130907/23167270/attachment-0001.htm>


More information about the asterisk-dev mailing list