lavf: Check the av_realloc return value in ff_dynarray_add

Message ID 1375101409-76315-1-git-send-email-martin@martin.st
State New
Headers show

Commit Message

Martin Storsjö July 29, 2013, 12:36 p.m.
This avoids crashes and leaks if the realloc fails. The failure
isn't signalled to the caller in any way, though.
---
 libavformat/cutils.c |    2 ++
 1 file changed, 2 insertions(+)

Comments

Luca Barbato July 29, 2013, 12:52 p.m. | #1
On 29/07/13 14:36, Martin Storsjö wrote:
> This avoids crashes and leaks if the realloc fails. The failure
> isn't signalled to the caller in any way, though.
> ---
>  libavformat/cutils.c |    2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libavformat/cutils.c b/libavformat/cutils.c
> index f58e152..75dc150 100644
> --- a/libavformat/cutils.c
> +++ b/libavformat/cutils.c
> @@ -36,6 +36,8 @@ void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem)
>          else
>              nb_alloc = nb * 2;
>          tab = av_realloc(tab, nb_alloc * sizeof(intptr_t));
> +        if (!tab)
> +            return;
>          *tab_ptr = tab;
>      }
>      tab[nb++] = elem;

We should fix it properly later, this bandaid is fine for now IMHO.

lu

Patch

diff --git a/libavformat/cutils.c b/libavformat/cutils.c
index f58e152..75dc150 100644
--- a/libavformat/cutils.c
+++ b/libavformat/cutils.c
@@ -36,6 +36,8 @@  void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem)
         else
             nb_alloc = nb * 2;
         tab = av_realloc(tab, nb_alloc * sizeof(intptr_t));
+        if (!tab)
+            return;
         *tab_ptr = tab;
     }
     tab[nb++] = elem;