diff mbox series

[FFmpeg-devel,08/10] avfilter/formats: Avoid redundant counter

Message ID AM7PR03MB66606D0E382963E5D0B346A38FFC9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 79595024ed887e2f473ec21ad3596af2c3fc4041
Headers show
Series [FFmpeg-devel,01/10] fftools/cmdutils: Use avfilter_pad_count() for AVFilter's number of pads | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Aug. 15, 2021, 9:55 a.m. UTC
The ff_set_common_(formats|channel_layouts|samplerates) have to free
their list in case it doesn't have an owner; therefore they tracked
whether they attached it to an owner. But the list's refcount already
contains such a counter, so we don't have to keep track of whether we
have attached the list to an owner.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavfilter/formats.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Nicolas George Aug. 20, 2021, 9:17 a.m. UTC | #1
Andreas Rheinhardt (12021-08-15):
> The ff_set_common_(formats|channel_layouts|samplerates) have to free
> their list in case it doesn't have an owner; therefore they tracked
> whether they attached it to an owner. But the list's refcount already
> contains such a counter, so we don't have to keep track of whether we
> have attached the list to an owner.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavfilter/formats.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)

Should be ok.

Regards,
diff mbox series

Patch

diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index 9e39d65a3c..cc73c5abcb 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -623,7 +623,7 @@  void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
 }
 
 #define SET_COMMON_FORMATS(ctx, fmts, ref_fn, unref_fn)             \
-    int count = 0, i;                                               \
+    int i;                                                          \
                                                                     \
     if (!fmts)                                                      \
         return AVERROR(ENOMEM);                                     \
@@ -634,7 +634,6 @@  void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
             if (ret < 0) {                                          \
                 return ret;                                         \
             }                                                       \
-            count++;                                                \
         }                                                           \
     }                                                               \
     for (i = 0; i < ctx->nb_outputs; i++) {                         \
@@ -643,13 +642,11 @@  void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
             if (ret < 0) {                                          \
                 return ret;                                         \
             }                                                       \
-            count++;                                                \
         }                                                           \
     }                                                               \
                                                                     \
-    if (!count) {                                                   \
+    if (!fmts->refcount)                                            \
         unref_fn(&fmts);                                            \
-    }                                                               \
                                                                     \
     return 0;