From: Steven Rostedt <rostedt@goodmis.org>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: linux-trace-devel@vger.kernel.org,
Daniel Wagner <dwagner@suse.de>,
Julia Lawall <julia.lawall@inria.fr>
Subject: Re: [PATCH RFC] libtraceevent: Improve exception handling in parse_arg_add()
Date: Mon, 13 Mar 2023 18:33:43 -0400 [thread overview]
Message-ID: <20230313183343.795c8c4f@gandalf.local.home> (raw)
In-Reply-To: <1e0fe72f-2dac-f825-7cd3-a5727654810a@web.de>
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
prev parent reply other threads:[~2023-03-13 22:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230313183343.795c8c4f@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=Markus.Elfring@web.de \
--cc=dwagner@suse.de \
--cc=julia.lawall@inria.fr \
--cc=linux-trace-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).