Use add_*flags only after compiler-specific configuration
[ffmpeg.git] / libavfilter / formats.c
index d7d0322..33fec16 100644 (file)
 
 #include "avfilter.h"
 
-/** merge and update all the references */
+/**
+ * Add all refs from a to ret and destroy a.
+ */
 static void merge_ref(AVFilterFormats *ret, AVFilterFormats *a)
 {
     int i;
+
     for(i = 0; i < a->refcount; i ++) {
         ret->refs[ret->refcount] = a->refs[i];
         *ret->refs[ret->refcount++] = ret;
     }
+
+    av_free(a->refs);
+    av_free(a->formats);
+    av_free(a);
 }
 
 AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
@@ -46,8 +53,9 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
             if(a->formats[i] == b->formats[j])
                 ret->formats[k++] = a->formats[i];
 
+    ret->format_count = k;
     /* check that there was at least one common format */
-    if(!(ret->format_count = k)) {
+    if(!ret->format_count) {
         av_free(ret->formats);
         av_free(ret);
         return NULL;
@@ -58,14 +66,6 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
     merge_ref(ret, a);
     merge_ref(ret, b);
 
-    av_free(a->refs);
-    av_free(a->formats);
-    av_free(a);
-
-    av_free(b->refs);
-    av_free(b->formats);
-    av_free(b);
-
     return ret;
 }
 
@@ -120,9 +120,9 @@ static int find_ref_index(AVFilterFormats **ref)
 
 void avfilter_formats_unref(AVFilterFormats **ref)
 {
-    int idx;
+    int idx = find_ref_index(ref);
 
-    if((idx = find_ref_index(ref)) >= 0)
+    if(idx >= 0)
         memmove((*ref)->refs + idx, (*ref)->refs + idx+1,
             sizeof(AVFilterFormats**) * ((*ref)->refcount-idx-1));
 
@@ -137,9 +137,9 @@ void avfilter_formats_unref(AVFilterFormats **ref)
 void avfilter_formats_changeref(AVFilterFormats **oldref,
                                 AVFilterFormats **newref)
 {
-    int idx;
+    int idx = find_ref_index(oldref);
 
-    if((idx = find_ref_index(oldref)) >= 0) {
+    if(idx >= 0) {
         (*oldref)->refs[idx] = newref;
         *newref = *oldref;
         *oldref = NULL;