On 18/09/13 14:26, Alexandra Khirnova wrote:
> also make functions use ff_dynarray directly instead of dynarray_add
> macro, macro is removed
> ---
>  libavformat/cutils.c      |   14 ++++++--
>  libavformat/hls.c         |    7 ++--
>  libavformat/hlsproto.c    |    7 ++--
>  libavformat/internal.h    |   17 +---------
>  libavformat/matroskadec.c |    8 +++--
>  libavformat/mpegtsenc.c   |    4 ++-
>  libavformat/rtpproto.c    |   17 +++++++---
>  libavformat/rtsp.c        |   80 
> +++++++++++++++++++++++++++++----------------
>  libavformat/rtspenc.c     |    5 ++-
>  libavformat/utils.c       |    6 ++--
>  10 files changed, 103 insertions(+), 62 deletions(-)
> 
> diff --git a/libavformat/cutils.c b/libavformat/cutils.c
> index f58e152..9ed0362 100644
> --- a/libavformat/cutils.c
> +++ b/libavformat/cutils.c
> @@ -22,10 +22,10 @@
>  #include "internal.h"
>  
>  /* add one element to a dynamic array */
> -void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem)
> +int ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem)
>  {
>      /* see similar avconv.c:grow_array() */
> -    int nb, nb_alloc;
> +    int nb, nb_alloc, i;
>      intptr_t *tab;
>  
>      nb = *nb_ptr;
> @@ -35,11 +35,19 @@ void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, 
> intptr_t elem)
>              nb_alloc = 1;
>          else
>              nb_alloc = nb * 2;
> -        tab = av_realloc(tab, nb_alloc * sizeof(intptr_t));
> +        tab = av_realloc(tab, nb_alloc * sizeof(*tab));
> +        if (!tab) {
> +            for (i = 0; i < nb; i++)
> +                av_freep(tab[i]);
> +            *nb_ptr = 0;
> +            return AVERROR(ENOMEM);
> +        }
>          *tab_ptr = tab;
>      }
>      tab[nb++] = elem;
>      *nb_ptr = nb;
> +
> +    return 0;

Please use the realloc_array.

> +                if ((err = ff_dynarray_add(&s->segments, &s->n_segments, 
> seg)) < 0)
> +                    return 0;

The return value shouldn't be err?

I'll re-read the rest later, but seems ok.

lu
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to