Re: [PATCH RFC] libtraceevent: Improve exception handling in parse_arg_add()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 12 Mar 2023 10:02:24 +0100
Markus Elfring <Markus.Elfring@xxxxxx> wrote:

> Hello,
> 
> I hope that the advice “If there is no cleanup needed then just return directly.”

                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


> can be taken better into account.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.3-rc1#n532
> 
> Another improvable implementation detail was detected by the means of
> the semantic patch language (Coccinelle software).
> How will the chances evolve to integrate the following change suggestion?
> 
> 
> diff --git a/src/event-parse.c b/src/event-parse.c
> index e655087..1ca5fdd 100644
> --- a/src/event-parse.c
> +++ b/src/event-parse.c
> @@ -6388,22 +6388,20 @@ static int parse_arg_add(struct tep_print_parse **parse, char *format,
>  
>      parg = calloc(1, sizeof(*parg));
>      if (!parg)
> -        goto error;
> +        return -1;
> +
>      parg->format = strdup(format);
> -    if (!parg->format)
> -        goto error;
> +    if (!parg->format) {
> +        free(parg);
           ^^^^^^^^^^

That's clean up.

-- Steve

> +        return -1;
> +    }
> +
>      parg->type = type;
>      parg->arg = arg;
>      parg->len_as_arg = len_as_arg;
>      parg->ls = ls;
>      *parse = parg;
>      return 0;
> -error:
> -    if (parg) {
> -        free(parg->format);
> -        free(parg);
> -    }
> -    return -1;
>  }
>  
>  static int parse_arg_format(struct tep_print_parse **parse,
> 
> 
> Regards,
> Markus




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux