From: Arnaldo Carvalho de Melo <acme@redhat.com>
To: Stephane Eranian <eranian@google.com>
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
mingo@elte.hu, dsahern@gmail.com
Subject: Re: [PATCH] perf: fix uninitialized variable in thread__set_comm()
Date: Fri, 7 Oct 2011 17:45:21 -0300 [thread overview]
Message-ID: <20111007204521.GA7813@ghostprotocols.net> (raw)
In-Reply-To: <CABPqkBQv9R1R7GPBMHf1V4BVmTyYopmdeKVCfy6-OZFiFX1CWw@mail.gmail.com>
Em Fri, Oct 07, 2011 at 12:14:18PM +0200, Stephane Eranian escreveu:
> Arnaldo,
>
> Did you also integrate this patch?
>
>
> On Tue, Sep 6, 2011 at 5:00 PM, Stephane Eranian <eranian@google.com> wrote:
> >
> > In thread__set_comm(), a command string could be freed and then
> > reused to point to a new command. Yet, the length was never reset
> > nor recomputed. This could lead to bogus column formatting.
Perhaps I'm out of coffee right now, but how can it be reused in such a
way?
I don't have a problem in doing the strlen in thread__set_comm, just
want to understand the sequence of events that lead to this
inconsistency.
- Arnaldo
> > This patch below fixes the problem by having thread__set_comm()
> > immediately compute the string length in thread->comm_len. It
> > gets rid of thread__comm_len() which is not needed anymore.
> > It was doing the lazy eval of strlen() which could cause the
> > issue.
> >
> > Signed-off-by: Stephane Eranian <eranian@google.com>
> > ---
> >
> > diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
> > index 677e1da..b883821 100644
> > --- a/tools/perf/util/hist.c
> > +++ b/tools/perf/util/hist.c
> > @@ -61,7 +61,7 @@ static void hists__calc_col_len(struct hists *self, struct hist_entry *h)
> > unresolved_col_width);
> > }
> >
> > - len = thread__comm_len(h->thread);
> > + len = h->thread->comm_len;
> > if (hists__new_col_len(self, HISTC_COMM, len))
> > hists__set_col_len(self, HISTC_THREAD, len + 6);
> >
> > @@ -731,7 +731,7 @@ static size_t hist_entry__fprintf_callchain(struct hist_entry *self,
> > struct sort_entry *se = list_first_entry(&hist_entry__sort_list,
> > typeof(*se), list);
> > left_margin = hists__col_len(hists, se->se_width_idx);
> > - left_margin -= thread__comm_len(self->thread);
> > + left_margin -= self->thread->comm_len;
> > }
> >
> > return hist_entry_callchain__fprintf(fp, self, session_total,
> > diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
> > index d5d3b22..3ce2a80 100644
> > --- a/tools/perf/util/thread.c
> > +++ b/tools/perf/util/thread.c
> > @@ -35,26 +35,18 @@ int thread__set_comm(struct thread *self, const char *comm)
> >
> > if (self->comm)
> > free(self->comm);
> > +
> > self->comm = strdup(comm);
> > +
> > err = self->comm == NULL ? -ENOMEM : 0;
> > if (!err) {
> > self->comm_set = true;
> > + self->comm_len = strlen(self->comm);
> > map_groups__flush(&self->mg);
> > }
> > return err;
> > }
> >
> > -int thread__comm_len(struct thread *self)
> > -{
> > - if (!self->comm_len) {
> > - if (!self->comm)
> > - return 0;
> > - self->comm_len = strlen(self->comm);
> > - }
> > -
> > - return self->comm_len;
> > -}
> > -
> > static size_t thread__fprintf(struct thread *self, FILE *fp)
> > {
> > return fprintf(fp, "Thread %d %s\n", self->pid, self->comm) +
> > diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
> > index e5f2401..701ea09 100644
> > --- a/tools/perf/util/thread.h
> > +++ b/tools/perf/util/thread.h
> > @@ -23,7 +23,6 @@ struct perf_session;
> > void thread__delete(struct thread *self);
> >
> > int thread__set_comm(struct thread *self, const char *comm);
> > -int thread__comm_len(struct thread *self);
> > struct thread *perf_session__findnew(struct perf_session *self, pid_t pid);
> > void thread__insert_map(struct thread *self, struct map *map);
> > int thread__fork(struct thread *self, struct thread *parent);
> >
next prev parent reply other threads:[~2011-10-07 20:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-06 15:00 [PATCH] perf: fix uninitialized variable in thread__set_comm() Stephane Eranian
2011-10-07 10:14 ` Stephane Eranian
2011-10-07 20:45 ` Arnaldo Carvalho de Melo [this message]
2011-10-07 21:53 ` Stephane Eranian
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=20111007204521.GA7813@ghostprotocols.net \
--to=acme@redhat.com \
--cc=dsahern@gmail.com \
--cc=eranian@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.