[FFmpeg-cvslog] rtmp: Don't try to do av_malloc(0)

Reimar Döffinger Reimar.Doeffinger at gmx.de
Thu May 26 19:21:55 CEST 2011


On Thu, May 26, 2011 at 03:32:24AM +0200, Martin Storsjö wrote:
> diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c
> index 63b0628..93790eb 100644
> --- a/libavformat/rtmppkt.c
> +++ b/libavformat/rtmppkt.c
> @@ -233,9 +233,11 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt,
>  int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type,
>                            int timestamp, int size)
>  {
> +    if (size) {
>      pkt->data = av_malloc(size);
>      if (!pkt->data)
>          return AVERROR(ENOMEM);
> +    }
>      pkt->data_size  = size;
>      pkt->channel_id = channel_id;
>      pkt->type       = type;
> diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
> index 70e4b14..f499bd3 100644
> --- a/libavformat/rtmpproto.c
> +++ b/libavformat/rtmpproto.c
> @@ -683,7 +683,7 @@ static int get_packet(URLContext *s, int for_header)
>          return AVERROR_EOF;
>  
>      for (;;) {
> -        RTMPPacket rpkt;
> +        RTMPPacket rpkt = { 0 };

Even if we ignore that this is a pointless obfuscation for us, it
has the issue that ff_rtmp_packet_create will no longer initialize
pkt->data on error, which seems like really bad code to me.
The initialization really should be done in ff_rtmp_packet_create
and not in each user of the function!


More information about the ffmpeg-cvslog mailing list