lavf: Avoid using av_malloc(0) in av_dump_format

Message ID 1317403998-15331-1-git-send-email-martin@martin.st
State Committed
Commit 151aaf539f0d1010471f916082742b3d80da1359
Headers show

Commit Message

Martin Storsjö Sept. 30, 2011, 5:33 p.m.
On OS X, av_malloc(0) returns pointers that cause crashes when
freed.
---
 libavformat/utils.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Comments

Anton Khirnov Sept. 30, 2011, 5:50 p.m. | #1
On Fri, 30 Sep 2011 20:33:18 +0300, Martin Storsjö <martin@martin.st> wrote:
> On OS X, av_malloc(0) returns pointers that cause crashes when
> freed.
> ---
>  libavformat/utils.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index d0ad358..0ba6fc3 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -3333,7 +3333,7 @@ void av_dump_format(AVFormatContext *ic,
>                      int is_output)
>  {
>      int i;
> -    uint8_t *printed = av_mallocz(ic->nb_streams);
> +    uint8_t *printed = ic->nb_streams ? av_mallocz(ic->nb_streams) : NULL;
>      if (ic->nb_streams && !printed)
>          return;
>  
> -- 
> 1.7.3.1
> 

Looks ok.
Martin Storsjö Sept. 30, 2011, 7:31 p.m. | #2
On Fri, 30 Sep 2011, Anton Khirnov wrote:

>
> On Fri, 30 Sep 2011 20:33:18 +0300, Martin Storsjö <martin@martin.st> wrote:
>> On OS X, av_malloc(0) returns pointers that cause crashes when
>> freed.
>> ---
>>  libavformat/utils.c |    2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/libavformat/utils.c b/libavformat/utils.c
>> index d0ad358..0ba6fc3 100644
>> --- a/libavformat/utils.c
>> +++ b/libavformat/utils.c
>> @@ -3333,7 +3333,7 @@ void av_dump_format(AVFormatContext *ic,
>>                      int is_output)
>>  {
>>      int i;
>> -    uint8_t *printed = av_mallocz(ic->nb_streams);
>> +    uint8_t *printed = ic->nb_streams ? av_mallocz(ic->nb_streams) : NULL;
>>      if (ic->nb_streams && !printed)
>>          return;
>>
>> --
>> 1.7.3.1
>>
>
> Looks ok.

Applied.

// Martin

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index d0ad358..0ba6fc3 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3333,7 +3333,7 @@  void av_dump_format(AVFormatContext *ic,
                     int is_output)
 {
     int i;
-    uint8_t *printed = av_mallocz(ic->nb_streams);
+    uint8_t *printed = ic->nb_streams ? av_mallocz(ic->nb_streams) : NULL;
     if (ic->nb_streams && !printed)
         return;