perf tool: basename cleanups
cover perf tool: basename cleanups
basename can modify strings passed to it, so the strings should not be marked const. Clean up the offenders and remove the BIONIC wrapper for libgen.h
Irina: Would you verify perf still compiles cleanly for Android. Thanks.
David Ahern (3):
perf annotate: make a copy of filename for passing to basename perf probe: make a copy of exec path for passing to basename perf tool: remove BIONIC wrapper around libgen.h
tools/perf/util/annotate.c | 9 ++++++++- tools/perf/util/probe-event.c | 12 ++++++++++-- tools/perf/util/symbol.h | 2 -- 3 files changed, 18 insertions(+), 5 deletions(-)
Signature · 1 line
1.7.10.1
PATCH 1/3 perf annotate: make a copy of filename for passing to basename
basename may modify the string passed to it, so the string should not be marked const.
--- tools/perf/util/annotate.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/annotate.c +8 -1
@@ -984,7 +984,8 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx, int context) {struct dso *dso = map->dso; -const char *filename = dso->long_name, *d_filename; +char *filename; +const char *d_filename;struct annotation *notes =symbol__annotation (sym);struct disasm_line *pos, *queue =NULL ;u64 start =map__rip_2objdump (map, sym->start);
@@ -992,6 +993,10 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx,int more =0 ;u64 len; + filename =strdup (dso->long_name); +if (!filename) +return -ENOMEM ; +if (full_paths) d_filename = filename;else
@@ -1042,6 +1047,8 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx, } } +free (filename); +return more; }
Signature · 1 line
1.7.10.1
[tip:perf/core] perf annotate: Make a copy of filename for passing to basename
Commit-ID: bfd14b9a7231e7cf77520bca1848c40c6b6360ae Gitweb: http://git.kernel.org/tip/bfd14b9a7231e7cf77520bca1848c40c6b6360ae Author: David Ahern <[email protected]> AuthorDate: Sat, 8 Sep 2012 09:06:50 -0600 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Sat, 8 Sep 2012 17:14:43 -0300
perf annotate: Make a copy of filename for passing to basename
The basename function may modify the string passed to it, so the string should not be marked const.
--- tools/perf/util/annotate.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
tools/perf/util/annotate.c +8 -1
@@ -984,7 +984,8 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx, int context) {struct dso *dso = map->dso; -const char *filename = dso->long_name, *d_filename; +char *filename; +const char *d_filename;struct annotation *notes =symbol__annotation (sym);struct disasm_line *pos, *queue =NULL ;u64 start =map__rip_2objdump (map, sym->start);
@@ -992,6 +993,10 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx,int more =0 ;u64 len; + filename =strdup (dso->long_name); +if (!filename) +return -ENOMEM ; +if (full_paths) d_filename = filename;else
@@ -1042,6 +1047,8 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx, } } +free (filename); +return more; }
PATCH 2/3 perf probe: make a copy of exec path for passing to basename
In reply to David Ahernbasename may modify the string passed to it, so the string should not be marked const.
--- tools/perf/util/probe-event.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
tools/perf/util/probe-event.c +10 -2
@@ -2307,10 +2307,17 @@ static int convert_name_to_addr(struct perf_probe_event *pev, const char *exec) function =NULL ; }if (!pev->group) { -char *ptr1, *ptr2; +char *ptr1, *ptr2, *exec_copy; pev->group =zalloc (sizeof (char *) *64 ); - ptr1 =strdup (basename (exec)); + exec_copy =strdup (exec); +if (!exec_copy) { + ret = -ENOMEM ; +pr_warning ("Failed to copy exec string.\n" ); + goto out; + } + + ptr1 =strdup (basename (exec_copy));if (ptr1) { ptr2 =strpbrk (ptr1,"-._" );if (ptr2)
@@ -2319,6 +2326,7 @@ static int convert_name_to_addr(struct perf_probe_event *pev, const char *exec) ptr1);free (ptr1); } +free (exec_copy); }free (pp->function); pp->function =zalloc (sizeof (char *) *MAX_PROBE_ARGS );
Signature · 1 line
1.7.10.1
[tip:perf/core] perf probe: Make a copy of exec path for passing to basename
Commit-ID: 1fb89448871500e5d5e7ad93d6dae68ee4fa464a Gitweb: http://git.kernel.org/tip/1fb89448871500e5d5e7ad93d6dae68ee4fa464a Author: David Ahern <[email protected]> AuthorDate: Sat, 8 Sep 2012 09:06:51 -0600 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Sat, 8 Sep 2012 17:15:04 -0300
perf probe: Make a copy of exec path for passing to basename
The basename function may modify the string passed to it, so the string should not be marked const.
--- tools/perf/util/probe-event.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
tools/perf/util/probe-event.c +10 -2
@@ -2307,10 +2307,17 @@ static int convert_name_to_addr(struct perf_probe_event *pev, const char *exec) function =NULL ; }if (!pev->group) { -char *ptr1, *ptr2; +char *ptr1, *ptr2, *exec_copy; pev->group =zalloc (sizeof (char *) *64 ); - ptr1 =strdup (basename (exec)); + exec_copy =strdup (exec); +if (!exec_copy) { + ret = -ENOMEM ; +pr_warning ("Failed to copy exec string.\n" ); + goto out; + } + + ptr1 =strdup (basename (exec_copy));if (ptr1) { ptr2 =strpbrk (ptr1,"-._" );if (ptr2)
@@ -2319,6 +2326,7 @@ static int convert_name_to_addr(struct perf_probe_event *pev, const char *exec) ptr1);free (ptr1); } +free (exec_copy); }free (pp->function); pp->function =zalloc (sizeof (char *) *MAX_PROBE_ARGS );
PATCH 3/3 perf tool: remove BIONIC wrapper around libgen.h
In reply to David AhernNow that the 2 offenders are fixed, the BIONIC conditional around libgen.h can be removed.
--- tools/perf/util/symbol.h | 2 -- 1 file changed, 2 deletions(-)
tools/perf/util/symbol.h +0 -2
@@ -10,9 +10,7 @@#include <linux/rbtree.h> #include <stdio.h> #include <byteswap.h> -#if defined(__BIONIC__)#include <libgen.h> -#endif #ifndef NO_LIBELF_SUPPORT #include <libelf.h>
Signature · 1 line
1.7.10.1
[tip:perf/core] perf symbols: Remove BIONIC wrapper around libgen. h
Commit-ID: 6c7f631261064762a8ba1ee34fc2b76d117ef3fa Gitweb: http://git.kernel.org/tip/6c7f631261064762a8ba1ee34fc2b76d117ef3fa Author: David Ahern <[email protected]> AuthorDate: Sat, 8 Sep 2012 09:06:52 -0600 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Sat, 8 Sep 2012 17:15:16 -0300
perf symbols: Remove BIONIC wrapper around libgen.h
Now that the 2 offenders are fixed, the BIONIC conditional around libgen.h can be removed.
--- tools/perf/util/symbol.h | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
tools/perf/util/symbol.h +0 -2
@@ -10,9 +10,7 @@#include <linux/rbtree.h> #include <stdio.h> #include <byteswap.h> -#if defined(__BIONIC__)#include <libgen.h> -#endif #ifndef NO_LIBELF_SUPPORT #include <libelf.h>
Quoted 5 lines · David Ahern
basename can modify strings passed to it, so the strings should not be marked const. Clean up the offenders and remove the BIONIC wrapper for
libgen.hIrina: Would you verify perf still compiles cleanly for Android. Thanks.
To all three patches:
Quoted 2 lines
Irina: Would you verify perf still compiles cleanly for Android. Thanks.
With these 3 patches perf still compiles cleanly for Android. Thanks for making the changes.
Irina