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

wdoekes reviewboard at asterisk.org
Fri Sep 6 17:56:19 CDT 2013


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

Ship it!


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;
}

- wdoekes


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/20130906/958f1547/attachment.htm>


More information about the asterisk-dev mailing list