Merge commit 'b94e4acb4874843e914fd3cb8e089aff0756bb4a'
authorMichael Niedermayer <michaelni@gmx.at>
Wed, 10 Oct 2012 11:18:05 +0000 (13:18 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 10 Oct 2012 11:18:05 +0000 (13:18 +0200)
* commit 'b94e4acb4874843e914fd3cb8e089aff0756bb4a':
  cmdutils_read_file: increment *size after writing the trailing \0
  af_resample: unref out_buf when avresample_convert returns 0
  af_amix: prevent memory leak on error path
  vc1dec: prevent memory leak in error path
  vc1dec: prevent memory leak on av_realloc error
  af_channelmap: free old extended_data on reallocation
  avconv: simplify memory allocation in copy_chapters
  matroskaenc: check cue point validity before reallocation
  swfenc: error out for more than 1 audio or video stream
  build: link test programs only against static libs

Conflicts:
ffmpeg_opt.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
cmdutils.c
ffmpeg_opt.c
libavcodec/vc1dec.c
libavfilter/af_amix.c
libavfilter/af_channelmap.c
libavfilter/af_resample.c
libavformat/matroskaenc.c
libavformat/swfenc.c
library.mak

index a820001..8ef477f 100644 (file)
@@ -1320,7 +1320,7 @@ int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
             ret = AVERROR_EOF;
     } else {
         ret = 0;
-        (*bufptr)[*size++] = '\0';
+        (*bufptr)[(*size)++] = '\0';
     }
 
     fclose(f);
index 26dcdff..4db881b 100644 (file)
@@ -1296,8 +1296,14 @@ static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata)
 {
     AVFormatContext *is = ifile->ctx;
     AVFormatContext *os = ofile->ctx;
+    AVChapter **tmp;
     int i;
 
+    tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters, sizeof(*os->chapters));
+    if (!tmp)
+        return AVERROR(ENOMEM);
+    os->chapters = tmp;
+
     for (i = 0; i < is->nb_chapters; i++) {
         AVChapter *in_ch = is->chapters[i], *out_ch;
         int64_t ts_off   = av_rescale_q(ofile->start_time - ifile->ts_offset,
@@ -1323,11 +1329,7 @@ static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata)
         if (copy_metadata)
             av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
 
-        os->nb_chapters++;
-        os->chapters = av_realloc_f(os->chapters, os->nb_chapters, sizeof(AVChapter));
-        if (!os->chapters)
-            return AVERROR(ENOMEM);
-        os->chapters[os->nb_chapters - 1] = out_ch;
+        os->chapters[os->nb_chapters++] = out_ch;
     }
     return 0;
 }
index e7085f6..639d317 100644 (file)
@@ -5369,9 +5369,10 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data,
                     break;
                 case VC1_CODE_FIELD: {
                     int buf_size3;
-                    slices = av_realloc(slices, sizeof(*slices) * (n_slices+1));
-                    if (!slices)
+                    tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1));
+                    if (!tmp)
                         goto err;
+                    slices = tmp;
                     slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
                     if (!slices[n_slices].buf)
                         goto err;
@@ -5393,9 +5394,10 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data,
                     break;
                 case VC1_CODE_SLICE: {
                     int buf_size3;
-                    slices = av_realloc(slices, sizeof(*slices) * (n_slices+1));
-                    if (!slices)
+                    tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1));
+                    if (!tmp)
                         goto err;
+                    slices = tmp;
                     slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
                     if (!slices[n_slices].buf)
                         goto err;
@@ -5466,7 +5468,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data,
 
     if (!s->context_initialized) {
         if (ff_msmpeg4_decode_init(avctx) < 0 || ff_vc1_decode_init_alloc_tables(v) < 0)
-            return -1;
+            goto err;
 
         s->low_delay = !avctx->has_b_frames || v->res_sprite;
 
index 9d0f998..c804cec 100644 (file)
@@ -280,8 +280,10 @@ static int output_frame(AVFilterLink *outlink, int nb_samples)
         return AVERROR(ENOMEM);
 
     in_buf = ff_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples);
-    if (!in_buf)
+    if (!in_buf) {
+        avfilter_unref_buffer(out_buf);
         return AVERROR(ENOMEM);
+    }
 
     for (i = 0; i < s->nb_inputs; i++) {
         if (s->input_state[i] == INPUT_ON) {
index 50289c3..211abd7 100644 (file)
@@ -337,8 +337,8 @@ static int channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *bu
             if (buf->extended_data == buf->data) {
                 buf->extended_data = new_extended_data;
             } else {
-                buf->extended_data = new_extended_data;
                 av_free(buf->extended_data);
+                buf->extended_data = new_extended_data;
             }
         } else if (buf->extended_data != buf->data) {
             av_free(buf->extended_data);
index 58a9b2a..c43d260 100644 (file)
@@ -194,9 +194,10 @@ static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
                                      buf_out->linesize[0], nb_samples,
                                      buf->extended_data, buf->linesize[0],
                                      buf->audio->nb_samples);
-        if (ret < 0) {
+        if (ret <= 0) {
             avfilter_unref_buffer(buf_out);
-            goto fail;
+            if (ret < 0)
+                goto fail;
         }
 
         av_assert0(!avresample_available(s->avr));
index 38518e3..375f728 100644 (file)
@@ -368,13 +368,13 @@ static int mkv_add_cuepoint(mkv_cues *cues, int stream, int64_t ts, int64_t clus
 {
     mkv_cuepoint *entries = cues->entries;
 
+    if (ts < 0)
+        return 0;
+
     entries = av_realloc(entries, (cues->num_entries + 1) * sizeof(mkv_cuepoint));
     if (entries == NULL)
         return AVERROR(ENOMEM);
 
-    if (ts < 0)
-        return 0;
-
     entries[cues->num_entries  ].pts = ts;
     entries[cues->num_entries  ].tracknum = stream + 1;
     entries[cues->num_entries++].cluster_pos = cluster_pos - cues->segment_offset;
index 4a5be12..b55f1a9 100644 (file)
@@ -187,6 +187,10 @@ static int swf_write_header(AVFormatContext *s)
     for(i=0;i<s->nb_streams;i++) {
         AVCodecContext *enc = s->streams[i]->codec;
         if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
+            if (swf->audio_enc) {
+                av_log(s, AV_LOG_ERROR, "SWF muxer only supports 1 audio stream\n");
+                return AVERROR_INVALIDDATA;
+            }
             if (enc->codec_id == AV_CODEC_ID_MP3) {
                 swf->audio_enc = enc;
                 swf->audio_fifo= av_fifo_alloc(AUDIO_FIFO_SIZE);
@@ -197,6 +201,10 @@ static int swf_write_header(AVFormatContext *s)
                 return -1;
             }
         } else {
+            if (swf->video_enc) {
+                av_log(s, AV_LOG_ERROR, "SWF muxer only supports 1 video stream\n");
+                return AVERROR_INVALIDDATA;
+            }
             if (enc->codec_id == AV_CODEC_ID_VP6F ||
                 enc->codec_id == AV_CODEC_ID_FLV1 ||
                 enc->codec_id == AV_CODEC_ID_MJPEG) {
index 821fe7e..cc77729 100644 (file)
@@ -35,7 +35,7 @@ install-libs-$(CONFIG_SHARED): install-lib$(NAME)-shared
 
 define RULES
 $(EXAMPLES) $(TESTPROGS) $(TOOLS): %$(EXESUF): %.o
-       $$(LD) $(LDFLAGS) $$(LD_O) $$^ $(FULLNAME:%=$(LD_LIB)) $(FFEXTRALIBS) $$(ELIBS)
+       $$(LD) $(LDFLAGS) $$(LD_O) $$^ $(FFEXTRALIBS) $$(ELIBS)
 
 $(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
        $(Q)cd ./$(SUBDIR) && $(LN_S) $(SLIBNAME_WITH_MAJOR) $(SLIBNAME)
@@ -94,8 +94,8 @@ endef
 
 $(eval $(RULES))
 
-$(EXAMPLES) $(TESTPROGS) $(TOOLS): $(THIS_LIB) $(DEP_LIBS)
-$(TESTPROGS): $(SUBDIR)$(LIBNAME)
+$(EXAMPLES) $(TOOLS): $(THIS_LIB) $(DEP_LIBS)
+$(TESTPROGS): $(SUBDIR)$(LIBNAME) $(DEP_LIBS)
 
 examples: $(EXAMPLES)
 testprogs: $(TESTPROGS)