Re: [PATCH perf/core v10 09/23] perf probe: Show all cached probes
From: Masami Hiramatsu
Date: Sat Jun 11 2016 - 23:21:06 EST
On Sat, 11 Jun 2016 09:28:09 +0900
Masami Hiramatsu <mhiramat@xxxxxxxxxx> wrote:
> On Thu, 9 Jun 2016 11:22:55 -0300
> Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> wrote:
>
> > Em Wed, Jun 08, 2016 at 06:30:30PM +0900, Masami Hiramatsu escreveu:
> > > +char *build_id_cache__origname(const char *sbuild_id)
> > > +{
> > > + char *linkname;
> > > + char buf[PATH_MAX];
> > > + char *ret = NULL, *p;
> > > + size_t offs = 5; /* == strlen("../..") */
> > > +
> > > + linkname = build_id_cache__linkname(sbuild_id, NULL, 0);
> > > + if (!linkname)
> > > + return NULL;
> > > +
> > > + if (readlink(linkname, buf, PATH_MAX) < 0)
> > > + goto out;
> > > + /* The link should be "../..<origpath>/<sbuild_id>" */
> > > + p = strrchr(buf, '/'); /* Cut off the "/<sbuild_id>" */
> > > + if (p && (p > buf + offs)) {
> > > + *p = '\0';
> > > + if (buf[offs + 1] == '[')
> > > + offs++; /*
> > > + * This is a DSO name, like [kernel.kallsyms].
> > > + * Skip the first '/', since this is not the
> > > + * cache of a regular file.
> > > + */
> > > + ret = strdup(buf + offs); /* Skip "../..[/]" */
> >
> > strdup can fail.
>
> Ah, right.
In this case, build_id_cache__origname() returns ret immediately(see below),
so we don't need to take reaction about that :)
> > > + }
> > > +out:
> > > + free(linkname);
> > > + return ret;
> > > +}
here, if strdup() fails, this just return NULL. that is OK.
Thanks!
--
Masami Hiramatsu <mhiramat@xxxxxxxxxx>