diff mbox series

[FFmpeg-devel,11/25] avfilter/af_headphone: Avoid duplicating string needlessly

Message ID 20200908211856.16290-11-andreas.rheinhardt@gmail.com
State Accepted
Commit bff1d0c6587243369f12c575f5dcb20d6e7e910b
Headers show
Series [FFmpeg-devel,01/25] avfilter/af_headphone: Don't use uninitialized buffer in log message | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 8, 2020, 9:18 p.m. UTC
The string given by an AVOption that contains the channel assignment
is used only once; ergo it doesn't matter that parsing the string via
av_strtok() is destructive. There is no need to make a copy.

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

Comments

Paul B Mahol Sept. 9, 2020, 1:18 a.m. UTC | #1
On Tue, Sep 08, 2020 at 11:18:42PM +0200, Andreas Rheinhardt wrote:
> The string given by an AVOption that contains the channel assignment
> is used only once; ergo it doesn't matter that parsing the string via
> av_strtok() is destructive. There is no need to make a copy.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavfilter/af_headphone.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)

Copy is needed to keep options state always known and reusable.

> 
> diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
> index 32939af854..967f8ed5a6 100644
> --- a/libavfilter/af_headphone.c
> +++ b/libavfilter/af_headphone.c
> @@ -100,16 +100,13 @@ static int parse_channel_name(const char *arg, uint64_t *rchannel)
>  static void parse_map(AVFilterContext *ctx)
>  {
>      HeadphoneContext *s = ctx->priv;
> -    char *arg, *tokenizer, *p, *args = av_strdup(s->map);
> +    char *arg, *tokenizer, *p;
>      uint64_t used_channels = 0;
>  
> -    if (!args)
> -        return;
> -    p = args;
> -
>      s->lfe_channel = -1;
>      s->nb_inputs = 1;
>  
> +    p = s->map;
>      while ((arg = av_strtok(p, "|", &tokenizer))) {
>          uint64_t out_channel;
>  
> @@ -133,8 +130,6 @@ static void parse_map(AVFilterContext *ctx)
>          s->nb_inputs = 2;
>      else
>          s->nb_inputs = s->nb_irs + 1;
> -
> -    av_free(args);
>  }
>  
>  typedef struct ThreadData {
> -- 
> 2.20.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 32939af854..967f8ed5a6 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -100,16 +100,13 @@  static int parse_channel_name(const char *arg, uint64_t *rchannel)
 static void parse_map(AVFilterContext *ctx)
 {
     HeadphoneContext *s = ctx->priv;
-    char *arg, *tokenizer, *p, *args = av_strdup(s->map);
+    char *arg, *tokenizer, *p;
     uint64_t used_channels = 0;
 
-    if (!args)
-        return;
-    p = args;
-
     s->lfe_channel = -1;
     s->nb_inputs = 1;
 
+    p = s->map;
     while ((arg = av_strtok(p, "|", &tokenizer))) {
         uint64_t out_channel;
 
@@ -133,8 +130,6 @@  static void parse_map(AVFilterContext *ctx)
         s->nb_inputs = 2;
     else
         s->nb_inputs = s->nb_irs + 1;
-
-    av_free(args);
 }
 
 typedef struct ThreadData {