linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH] trace-cmd: Check all strdup() return values
Date: Fri, 2 Jun 2023 22:50:09 -0400	[thread overview]
Message-ID: <20230602225009.10050479@rorschach.local.home> (raw)
In-Reply-To: <6f7e3c23-4e14-ea96-e8c3-d3bc0c192c91@web.de>

On Fri, 2 Jun 2023 17:52:27 +0200
Markus Elfring <Markus.Elfring@web.de> wrote:

> …
> > +++ b/lib/trace-cmd/trace-input.c  
> …
> > @@ -5967,9 +5974,15 @@ tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx)
> >  	new_handle->parent = handle;
> >  	new_handle->cpustats = NULL;
> >  	new_handle->hooks = NULL;
> > -	if (handle->uname)
> > +	if (handle->uname) {
> >  		/* Ignore if fails to malloc, no biggy */
> >  		new_handle->uname = strdup(handle->uname);
> > +		if (new_handle->uname == NULL) {
> > +			free(new_handle->trace_clock);
> > +			free(new_handle);
> > +			return NULL;
> > +		}
> > +	}
> >  	tracecmd_ref(handle);
> >
> >  	new_handle->fd = dup(handle->fd);  
> 
> Did the shown comment line become outdated with this change approach?

No, the comment is correct. Thanks for pointing that out. This is what
I get when I use scripts for changes.

> 
> 
> …
> > +++ b/tracecmd/trace-record.c  
> …
> > @@ -371,8 +373,11 @@ struct buffer_instance
> > *allocate_instance(const char *name) instance = calloc(1,
> > sizeof(*instance)); if (!instance)
> >  		return NULL;
> > -	if (name)
> > +	if (name) {
> >  		instance->name = strdup(name);
> > +		if (instance->name == NULL)
> > +			goto error;
> > +	}
> >  	if (tracefs_instance_exists(name)) {
> >  		instance->tracefs = tracefs_instance_create(name);
> >  		if (!instance->tracefs)  
> 
> I hope that more appropriate labels can be applied.
> 
> See also:
> * Improve exception handling in allocate_instance()
>   https://bugzilla.kernel.org/show_bug.cgi?id=217128
> 
> *
> https://wiki.sei.cmu.edu/confluence/display/c/MEM12-C.+Consider+using+a+goto+chain+when+leaving+a+function+on+error+when+using+and+releasing+resources#MEM12C.Considerusingagotochainwhenleavingafunctiononerrorwhenusingandreleasingresources-CompliantSolution%28POSIX,GotoChain%29
> 
> * Completion of error handling
>   https://bugzilla.kernel.org/show_bug.cgi?id=217126

For the application, this is good enough.

-- Steve

      parent reply	other threads:[~2023-06-03  2:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-02  5:45 [PATCH] trace-cmd: Check all strdup() return values Steven Rostedt
     [not found] ` <6f7e3c23-4e14-ea96-e8c3-d3bc0c192c91@web.de>
2023-06-03  2:50   ` 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=20230602225009.10050479@rorschach.local.home \
    --to=rostedt@goodmis.org \
    --cc=Markus.Elfring@web.de \
    --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).