rtmp: Don't try to do av_malloc(0)
authorMartin Storsjö <martin@martin.st>
Wed, 25 May 2011 16:08:29 +0000 (19:08 +0300)
committerMartin Storsjö <martin@martin.st>
Wed, 25 May 2011 19:00:42 +0000 (22:00 +0300)
Some received packets can have size 0. The return value from
av_malloc(0) may be NULL, which is ok if the size was 0. On
OS X, however, the returned pointer is non-null but leads to
crashes when trying to free it.

Signed-off-by: Martin Storsjö <martin@martin.st>
libavformat/rtmppkt.c
libavformat/rtmpproto.c

index 63b0628799931662c66f050b0aad44bdfce73adc..93790eb5250f7d0e66f50ceb7c700a7851653b23 100644 (file)
@@ -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;
index 70e4b142d61d25cc5915737879d0f1bfe538250a..f499bd3b71cf56da058be2f1108d37ae0f7a8633 100644 (file)
@@ -683,7 +683,7 @@ static int get_packet(URLContext *s, int for_header)
         return AVERROR_EOF;
 
     for (;;) {
-        RTMPPacket rpkt;
+        RTMPPacket rpkt = { 0 };
         if ((ret = ff_rtmp_packet_read(rt->stream, &rpkt,
                                        rt->chunk_size, rt->prev_pkt[0])) <= 0) {
             if (ret == 0) {