[FFmpeg-cvslog] avfilter/formats: proper error handling in ff_channel_layouts_ref() and ff_formats_ref()

Clément Bœsch git at videolan.org
Mon Mar 16 23:43:22 CET 2015


ffmpeg | branch: master | Clément Bœsch <u at pkh.me> | Sat Mar 14 21:21:49 2015 +0100| [f861d9b2c64752b134d49cb9e790b77221c381c1] | committer: Clément Bœsch

avfilter/formats: proper error handling in ff_channel_layouts_ref() and ff_formats_ref()

Also make sure the allocation and its check are properly done.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f861d9b2c64752b134d49cb9e790b77221c381c1
---

 libavfilter/formats.c |   22 +++++++++++-----------
 libavfilter/formats.h |    6 +++---
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index 896ceeb..6393416 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -400,21 +400,21 @@ AVFilterChannelLayouts *ff_all_channel_counts(void)
     return ret;
 }
 
-#define FORMATS_REF(f, ref)                                          \
-do {                                                                 \
-    *ref = f;                                                        \
-    f->refs = av_realloc(f->refs, sizeof(*f->refs) * ++f->refcount); \
-    if (!f->refs)                                                    \
-        return;                                                      \
-    f->refs[f->refcount-1] = ref;                                    \
-} while (0)
-
-void ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
+#define FORMATS_REF(f, ref)                                                     \
+    void *tmp = av_realloc_array(f->refs, sizeof(*f->refs), f->refcount + 1);   \
+    if (!tmp)                                                                   \
+        return AVERROR(ENOMEM);                                                 \
+    f->refs = tmp;                                                              \
+    f->refs[f->refcount++] = ref;                                               \
+    *ref = f;                                                                   \
+    return 0
+
+int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
 {
     FORMATS_REF(f, ref);
 }
 
-void ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
+int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
 {
     FORMATS_REF(f, ref);
 }
diff --git a/libavfilter/formats.h b/libavfilter/formats.h
index 468eac8..f94855d 100644
--- a/libavfilter/formats.h
+++ b/libavfilter/formats.h
@@ -159,8 +159,8 @@ int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout);
 /**
  * Add *ref as a new reference to f.
  */
-void ff_channel_layouts_ref(AVFilterChannelLayouts *f,
-                            AVFilterChannelLayouts **ref);
+int ff_channel_layouts_ref(AVFilterChannelLayouts *f,
+                           AVFilterChannelLayouts **ref);
 
 /**
  * Remove a reference to a channel layouts list.
@@ -233,7 +233,7 @@ AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b,
  *  | |____| |    | |____|
  *  |________|    |________________________
  */
-void ff_formats_ref(AVFilterFormats *formats, AVFilterFormats **ref);
+int ff_formats_ref(AVFilterFormats *formats, AVFilterFormats **ref);
 
 /**
  * If *ref is non-NULL, remove *ref as a reference to the format list



More information about the ffmpeg-cvslog mailing list