diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index ce61f79dbaae81344e2b41734edea211fcb33e29..d8cd038baed267335891ac87ed4477fc886e5c6e 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -123,6 +123,17 @@ static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char * */ lc = setlocale(LC_NUMERIC, NULL); + /* + * The lc string may be allocated in static storage, + * so get a dynamic copy to make it survive setlocale + * call below. + */ + lc = strdup(lc); + if (!lc) { + ret = -ENOMEM; + goto error; + } + /* * force to C locale to ensure kernel * scale string is converted correctly. @@ -135,6 +146,8 @@ static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char * /* restore locale */ setlocale(LC_NUMERIC, lc); + free((char *) lc); + ret = 0; error: close(fd);