perf symbols: Remove open coded management of long_name_allocated member

Instead of expecting callers to set this member accodingly so that later
at dso destruction it can, if needed, be correctly free()d, make it a
requirement by passing it as a parameter to dso__set_long_name.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-na7t1tqim22vuqkt4zq5n4ri@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 5230fb7d
...@@ -386,12 +386,17 @@ struct dso *dso__kernel_findnew(struct machine *machine, const char *name, ...@@ -386,12 +386,17 @@ struct dso *dso__kernel_findnew(struct machine *machine, const char *name,
return dso; return dso;
} }
void dso__set_long_name(struct dso *dso, char *name) void dso__set_long_name(struct dso *dso, char *name, bool name_allocated)
{ {
if (name == NULL) if (name == NULL)
return; return;
dso->long_name = name;
dso->long_name_len = strlen(name); if (dso->long_name_allocated)
free(dso->long_name);
dso->long_name = name;
dso->long_name_len = strlen(name);
dso->long_name_allocated = name_allocated;
} }
void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated) void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated)
...@@ -444,7 +449,7 @@ struct dso *dso__new(const char *name) ...@@ -444,7 +449,7 @@ struct dso *dso__new(const char *name)
if (dso != NULL) { if (dso != NULL) {
int i; int i;
strcpy(dso->name, name); strcpy(dso->name, name);
dso__set_long_name(dso, dso->name); dso__set_long_name(dso, dso->name, false);
dso__set_short_name(dso, dso->name, false); dso__set_short_name(dso, dso->name, false);
for (i = 0; i < MAP__NR_TYPES; ++i) for (i = 0; i < MAP__NR_TYPES; ++i)
dso->symbols[i] = dso->symbol_names[i] = RB_ROOT; dso->symbols[i] = dso->symbol_names[i] = RB_ROOT;
......
...@@ -111,7 +111,7 @@ struct dso *dso__new(const char *name); ...@@ -111,7 +111,7 @@ struct dso *dso__new(const char *name);
void dso__delete(struct dso *dso); void dso__delete(struct dso *dso);
void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated); void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated);
void dso__set_long_name(struct dso *dso, char *name); void dso__set_long_name(struct dso *dso, char *name, bool name_allocated);
int dso__name_len(const struct dso *dso); int dso__name_len(const struct dso *dso);
......
...@@ -763,8 +763,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *mg, ...@@ -763,8 +763,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *mg,
ret = -1; ret = -1;
goto out; goto out;
} }
dso__set_long_name(map->dso, long_name); dso__set_long_name(map->dso, long_name, true);
map->dso->long_name_allocated = 1;
dso__kernel_module_get_build_id(map->dso, ""); dso__kernel_module_get_build_id(map->dso, "");
} }
} }
......
...@@ -1159,7 +1159,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map, ...@@ -1159,7 +1159,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
dso->data_type = DSO_BINARY_TYPE__GUEST_KCORE; dso->data_type = DSO_BINARY_TYPE__GUEST_KCORE;
else else
dso->data_type = DSO_BINARY_TYPE__KCORE; dso->data_type = DSO_BINARY_TYPE__KCORE;
dso__set_long_name(dso, strdup(kcore_filename)); dso__set_long_name(dso, strdup(kcore_filename), true);
close(fd); close(fd);
...@@ -1438,8 +1438,7 @@ int dso__load_vmlinux(struct dso *dso, struct map *map, ...@@ -1438,8 +1438,7 @@ int dso__load_vmlinux(struct dso *dso, struct map *map,
dso->data_type = DSO_BINARY_TYPE__GUEST_VMLINUX; dso->data_type = DSO_BINARY_TYPE__GUEST_VMLINUX;
else else
dso->data_type = DSO_BINARY_TYPE__VMLINUX; dso->data_type = DSO_BINARY_TYPE__VMLINUX;
dso__set_long_name(dso, (char *)vmlinux); dso__set_long_name(dso, (char *)vmlinux, vmlinux_allocated);
dso->long_name_allocated = vmlinux_allocated;
dso__set_loaded(dso, map->type); dso__set_loaded(dso, map->type);
pr_debug("Using %s for symbols\n", symfs_vmlinux); pr_debug("Using %s for symbols\n", symfs_vmlinux);
} }
...@@ -1631,7 +1630,7 @@ static int dso__load_kernel_sym(struct dso *dso, struct map *map, ...@@ -1631,7 +1630,7 @@ static int dso__load_kernel_sym(struct dso *dso, struct map *map,
free(kallsyms_allocated_filename); free(kallsyms_allocated_filename);
if (err > 0 && !dso__is_kcore(dso)) { if (err > 0 && !dso__is_kcore(dso)) {
dso__set_long_name(dso, strdup("[kernel.kallsyms]")); dso__set_long_name(dso, strdup("[kernel.kallsyms]"), true);
map__fixup_start(map); map__fixup_start(map);
map__fixup_end(map); map__fixup_end(map);
} }
...@@ -1679,7 +1678,7 @@ static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map, ...@@ -1679,7 +1678,7 @@ static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map,
pr_debug("Using %s for symbols\n", kallsyms_filename); pr_debug("Using %s for symbols\n", kallsyms_filename);
if (err > 0 && !dso__is_kcore(dso)) { if (err > 0 && !dso__is_kcore(dso)) {
machine__mmap_name(machine, path, sizeof(path)); machine__mmap_name(machine, path, sizeof(path));
dso__set_long_name(dso, strdup(path)); dso__set_long_name(dso, strdup(path), true);
map__fixup_start(map); map__fixup_start(map);
map__fixup_end(map); map__fixup_end(map);
} }
......
...@@ -103,7 +103,7 @@ struct dso *vdso__dso_findnew(struct list_head *head) ...@@ -103,7 +103,7 @@ struct dso *vdso__dso_findnew(struct list_head *head)
dso = dso__new(VDSO__MAP_NAME); dso = dso__new(VDSO__MAP_NAME);
if (dso != NULL) { if (dso != NULL) {
dsos__add(head, dso); dsos__add(head, dso);
dso__set_long_name(dso, file); dso__set_long_name(dso, file, false);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment