Merge remote-tracking branch 'qatar/master'
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 4 Apr 2013 12:30:41 +0000 (14:30 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 4 Apr 2013 12:35:40 +0000 (14:35 +0200)
* qatar/master:
  xmv: do not leak memory in the error paths in xmv_read_header()

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavformat/xmv.c

@@@ -180,28 -183,36 +180,30 @@@ static int xmv_read_header(AVFormatCont
  
      avio_skip(pb, 2); /* Unknown (padding?) */
  
 -    xmv->audio_tracks = av_malloc(xmv->audio_track_count * sizeof(XMVAudioTrack));
 -    if (!xmv->audio_tracks)
 -        return AVERROR(ENOMEM);
 -
      xmv->audio = av_malloc(xmv->audio_track_count * sizeof(XMVAudioPacket));
-     if (!xmv->audio)
-         return AVERROR(ENOMEM);
+     if (!xmv->audio) {
+         ret = AVERROR(ENOMEM);
+         goto fail;
+     }
  
      for (audio_track = 0; audio_track < xmv->audio_track_count; audio_track++) {
 -        XMVAudioTrack  *track  = &xmv->audio_tracks[audio_track];
 -        XMVAudioPacket *packet = &xmv->audio       [audio_track];
 +        XMVAudioPacket *packet = &xmv->audio[audio_track];
          AVStream *ast = NULL;
  
 -        track->compression     = avio_rl16(pb);
 -        track->channels        = avio_rl16(pb);
 -        track->sample_rate     = avio_rl32(pb);
 -        track->bits_per_sample = avio_rl16(pb);
 -        track->flags           = avio_rl16(pb);
 -
 -        track->bit_rate      = track->bits_per_sample *
 -                               track->sample_rate *
 -                               track->channels;
 -        track->block_align   = 36 * track->channels;
 -        track->block_samples = 64;
 -        track->codec_id      = ff_wav_codec_get_id(track->compression,
 -                                                   track->bits_per_sample);
 -
 -        packet->track        = track;
 +        packet->compression     = avio_rl16(pb);
 +        packet->channels        = avio_rl16(pb);
 +        packet->sample_rate     = avio_rl32(pb);
 +        packet->bits_per_sample = avio_rl16(pb);
 +        packet->flags           = avio_rl16(pb);
 +
 +        packet->bit_rate      = packet->bits_per_sample *
 +                                packet->sample_rate *
 +                                packet->channels;
 +        packet->block_align   = 36 * packet->channels;
 +        packet->block_samples = 64;
 +        packet->codec_id      = ff_wav_codec_get_id(packet->compression,
 +                                                    packet->bits_per_sample);
 +
          packet->stream_index = -1;
  
          packet->frame_size  = 0;
          }
  
          ast = avformat_new_stream(s, NULL);
-         if (!ast)
-             return AVERROR(ENOMEM);
+         if (!ast) {
+             ret = AVERROR(ENOMEM);
+             goto fail;
+         }
  
          ast->codec->codec_type            = AVMEDIA_TYPE_AUDIO;
 -        ast->codec->codec_id              = track->codec_id;
 -        ast->codec->codec_tag             = track->compression;
 -        ast->codec->channels              = track->channels;
 -        ast->codec->sample_rate           = track->sample_rate;
 -        ast->codec->bits_per_coded_sample = track->bits_per_sample;
 -        ast->codec->bit_rate              = track->bit_rate;
 -        ast->codec->block_align           = 36 * track->channels;
 +        ast->codec->codec_id              = packet->codec_id;
 +        ast->codec->codec_tag             = packet->compression;
 +        ast->codec->channels              = packet->channels;
 +        ast->codec->sample_rate           = packet->sample_rate;
 +        ast->codec->bits_per_coded_sample = packet->bits_per_sample;
 +        ast->codec->bit_rate              = packet->bit_rate;
 +        ast->codec->block_align           = 36 * packet->channels;
  
 -        avpriv_set_pts_info(ast, 32, track->block_samples, track->sample_rate);
 +        avpriv_set_pts_info(ast, 32, packet->block_samples, packet->sample_rate);
  
          packet->stream_index = ast->index;