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

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

 



On Mon, 13 Mar 2023 21:35:38 +0100
Markus Elfring <Markus.Elfring@xxxxxx> wrote:

> >> 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;
> >> +  
> 
> The first failed memory allocation does not need clean-up.
> 
> 
> >>      parg->format = strdup(format);
> >> -    if (!parg->format)
> >> -        goto error;
> >> +    if (!parg->format) {
> >> +        free(parg);  
> >            ^^^^^^^^^^
> >
> > That's clean up.  
> 
> Yes. ‒ I propose to move a single memory release into an if branch
> as a known design approach for better exception handling.

This has nothing to do with clean ups, but personal preferences. Neither is
more correct than the other. Both work. I prefer the code as is. End of
discussion.

-- Steve



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

  Powered by Linux