perf symbols: Fix directory descriptor leaking

When I ran "perf kvm ... top", I encountered the following error output.

  Error: perfcounter syscall returned with -1 (Too many open files)

  Fatal: No CONFIG_PERF_EVENTS=y kernel support configured?

Looking into perf, I found perf opens too many directories at
initialization time, but forgets to close them. Here is the fix.

LKML-Reference: <4C230362.5080704@cn.fujitsu.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Gui Jianfeng 2010-06-24 15:04:02 +08:00 коммит произвёл Arnaldo Carvalho de Melo
Родитель 58c3439083
Коммит 74534341c1
1 изменённых файлов: 10 добавлений и 7 удалений

Просмотреть файл

@ -1443,6 +1443,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *self,
{ {
struct dirent *dent; struct dirent *dent;
DIR *dir = opendir(dir_name); DIR *dir = opendir(dir_name);
int ret = 0;
if (!dir) { if (!dir) {
pr_debug("%s: cannot open %s dir\n", __func__, dir_name); pr_debug("%s: cannot open %s dir\n", __func__, dir_name);
@ -1465,8 +1466,9 @@ static int map_groups__set_modules_path_dir(struct map_groups *self,
snprintf(path, sizeof(path), "%s/%s", snprintf(path, sizeof(path), "%s/%s",
dir_name, dent->d_name); dir_name, dent->d_name);
if (map_groups__set_modules_path_dir(self, path) < 0) ret = map_groups__set_modules_path_dir(self, path);
goto failure; if (ret < 0)
goto out;
} else { } else {
char *dot = strrchr(dent->d_name, '.'), char *dot = strrchr(dent->d_name, '.'),
dso_name[PATH_MAX]; dso_name[PATH_MAX];
@ -1487,17 +1489,18 @@ static int map_groups__set_modules_path_dir(struct map_groups *self,
dir_name, dent->d_name); dir_name, dent->d_name);
long_name = strdup(path); long_name = strdup(path);
if (long_name == NULL) if (long_name == NULL) {
goto failure; ret = -1;
goto out;
}
dso__set_long_name(map->dso, long_name); dso__set_long_name(map->dso, long_name);
dso__kernel_module_get_build_id(map->dso, ""); dso__kernel_module_get_build_id(map->dso, "");
} }
} }
return 0; out:
failure:
closedir(dir); closedir(dir);
return -1; return ret;
} }
static char *get_kernel_version(const char *root_dir) static char *get_kernel_version(const char *root_dir)