[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20141024153513.GG14687@kernel.org>
Date: Fri, 24 Oct 2014 12:35:13 -0300
From: Arnaldo Carvalho de Melo <acme@...nel.org>
To: Adrian Hunter <adrian.hunter@...el.com>
Cc: Namhyung Kim <namhyung@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
linux-kernel@...r.kernel.org, David Ahern <dsahern@...il.com>,
Frederic Weisbecker <fweisbec@...il.com>,
Jiri Olsa <jolsa@...hat.com>,
Paul Mackerras <paulus@...ba.org>,
Stephane Eranian <eranian@...gle.com>
Subject: Re: [PATCH 02/16] perf pmu: Let pmu's with no events show up on perf
list
Em Fri, Oct 24, 2014 at 11:45:00AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Oct 24, 2014 at 05:36:46PM +0300, Adrian Hunter escreveu:
> > >+ aliases = zalloc(sizeof(char *) * len);
> > > if (!aliases)
> > >- return;
> > >+ goto out_enomem;
> >
> > That path tries to free aliases[j] but aliases is null. You could set len to 0 in that case.
You got me confused, yeah, it ended up a bit confusing, but the idea was
to share the error message, i.e. have just one printf("FATAL:
enomem"...) for both alloc failures, the later will have to free the
array elements, and it is ok to call free(NULL), thus the change from
malloc to zalloc(aliases), so that all its entries were zeroed, yadda,
yadda.
- Arnaldo
>
> Oops, yeah, my bad, it should not have the !, fixing...
>
> > > pmu = NULL;
> > > j = 0;
> > > while ((pmu = perf_pmu__scan(pmu)) != NULL) {
> > >@@ -768,16 +768,20 @@ void print_pmu_events(const char *event_glob, bool name_only)
> > > (!is_cpu && strglobmatch(alias->name,
> > > event_glob))))
> > > continue;
> > >- aliases[j] = name;
> > >+
> > > if (is_cpu && !name_only)
> > >- aliases[j] = format_alias_or(buf, sizeof(buf),
> > >- pmu, alias);
> > >- aliases[j] = strdup(aliases[j]);
> > >+ name = format_alias_or(buf, sizeof(buf), pmu, alias);
> > >+
> > >+ aliases[j] = strdup(name);
> > >+ if (aliases[j] == NULL)
> > >+ goto out_enomem;
> > > j++;
> > > }
> > > if (pmu->selectable) {
> > >- scnprintf(buf, sizeof(buf), "%s//", pmu->name);
> > >- aliases[j] = strdup(buf);
> > >+ char *s;
> > >+ if (asprintf(&s, "%s//", pmu->name) < 0)
> > >+ goto out_enomem;
> > >+ aliases[j] = s;
> > > j++;
> > > }
> > > }
> > >@@ -789,12 +793,20 @@ void print_pmu_events(const char *event_glob, bool name_only)
> > > continue;
> > > }
> > > printf(" %-50s [Kernel PMU event]\n", aliases[j]);
> > >- zfree(&aliases[j]);
> > > printed++;
> > > }
> > > if (printed)
> > > printf("\n");
> > >- free(aliases);
> > >+out_free:
> > >+ for (j = 0; j < len; j++)
> > >+ zfree(&aliases[j]);
> > >+ zfree(&aliases);
> > >+ return;
> > >+
> > >+out_enomem:
> > >+ printf("FATAL: not enough memory to print PMU events\n");
> > >+ if (aliases)
> > >+ goto out_free;
> > > }
> > >
> > > bool pmu_have_event(const char *pname, const char *name)
> > >
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists