* Re: [PATCH RFC] libtraceevent: Improve exception handling in parse_arg_add() [not found] <94b6775c-406e-4b17-2984-84f1bb54f375@web.de> @ 2023-03-13 16:16 ` Steven Rostedt [not found] ` <1e0fe72f-2dac-f825-7cd3-a5727654810a@web.de> 0 siblings, 1 reply; 2+ messages in thread From: Steven Rostedt @ 2023-03-13 16:16 UTC (permalink / raw) To: Markus Elfring; +Cc: linux-trace-devel, Daniel Wagner, Julia Lawall On Sun, 12 Mar 2023 10:02:24 +0100 Markus Elfring <Markus.Elfring@web.de> 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 ^ permalink raw reply [flat|nested] 2+ messages in thread
[parent not found: <1e0fe72f-2dac-f825-7cd3-a5727654810a@web.de>]
* Re: [PATCH RFC] libtraceevent: Improve exception handling in parse_arg_add() [not found] ` <1e0fe72f-2dac-f825-7cd3-a5727654810a@web.de> @ 2023-03-13 22:33 ` Steven Rostedt 0 siblings, 0 replies; 2+ messages in thread From: Steven Rostedt @ 2023-03-13 22:33 UTC (permalink / raw) To: Markus Elfring; +Cc: linux-trace-devel, Daniel Wagner, Julia Lawall On Mon, 13 Mar 2023 21:35:38 +0100 Markus Elfring <Markus.Elfring@web.de> 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 ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-13 22:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <94b6775c-406e-4b17-2984-84f1bb54f375@web.de>
2023-03-13 16:16 ` [PATCH RFC] libtraceevent: Improve exception handling in parse_arg_add() Steven Rostedt
[not found] ` <1e0fe72f-2dac-f825-7cd3-a5727654810a@web.de>
2023-03-13 22:33 ` Steven Rostedt
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).