aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/probe-finder.c
diff options
context:
space:
mode:
authorMasami Hiramatsu <mhiramat@redhat.com>2010-04-12 13:17:56 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-04-14 16:28:52 -0400
commit02b95dadc8a1d2c302513e5fa24c492380d26e93 (patch)
treeebaf199b33a1ba6c2165a8f39d985080a048ba22 /tools/perf/util/probe-finder.c
parente334016f1d7250a6523b3a44ccecfe23af6e2f57 (diff)
perf probe: Remove xstrdup()/xstrndup() from util/probe-{event, finder}.c
Remove all xstr*dup() calls from util/probe-{event,finder}.c since it may cause 'sudden death' in utility functions and it makes reusing it from other code difficult. Cc: Ingo Molnar <mingo@elte.hu> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Frederic Weisbecker <fweisbec@gmail.com> LKML-Reference: <20100412171756.3790.89607.stgit@localhost6.localdomain6> Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/probe-finder.c')
-rw-r--r--tools/perf/util/probe-finder.c58
1 files changed, 43 insertions, 15 deletions
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index ce1ac827f3d2..e443e69a4d2e 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -424,7 +424,10 @@ static int convert_location(Dwarf_Op *op, struct probe_finder *pf)
424 return -ERANGE; 424 return -ERANGE;
425 } 425 }
426 426
427 tvar->value = xstrdup(regs); 427 tvar->value = strdup(regs);
428 if (tvar->value == NULL)
429 return -ENOMEM;
430
428 if (ref) { 431 if (ref) {
429 tvar->ref = zalloc(sizeof(struct kprobe_trace_arg_ref)); 432 tvar->ref = zalloc(sizeof(struct kprobe_trace_arg_ref));
430 if (tvar->ref == NULL) 433 if (tvar->ref == NULL)
@@ -466,7 +469,9 @@ static int convert_variable_type(Dwarf_Die *vr_die,
466 strerror(-ret)); 469 strerror(-ret));
467 return ret; 470 return ret;
468 } 471 }
469 targ->type = xstrdup(buf); 472 targ->type = strdup(buf);
473 if (targ->type == NULL)
474 return -ENOMEM;
470 } 475 }
471 return 0; 476 return 0;
472} 477}
@@ -576,9 +581,11 @@ static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
576 vr_die = &die_mem; 581 vr_die = &die_mem;
577 } 582 }
578 if (ret == 0) { 583 if (ret == 0) {
579 if (pf->pvar->type) 584 if (pf->pvar->type) {
580 pf->tvar->type = xstrdup(pf->pvar->type); 585 pf->tvar->type = strdup(pf->pvar->type);
581 else 586 if (pf->tvar->type == NULL)
587 ret = -ENOMEM;
588 } else
582 ret = convert_variable_type(vr_die, pf->tvar); 589 ret = convert_variable_type(vr_die, pf->tvar);
583 } 590 }
584 /* *expr will be cached in libdw. Don't free it. */ 591 /* *expr will be cached in libdw. Don't free it. */
@@ -595,22 +602,30 @@ static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf)
595{ 602{
596 Dwarf_Die vr_die; 603 Dwarf_Die vr_die;
597 char buf[32], *ptr; 604 char buf[32], *ptr;
605 int ret;
598 606
599 /* TODO: Support arrays */ 607 /* TODO: Support arrays */
600 if (pf->pvar->name) 608 if (pf->pvar->name)
601 pf->tvar->name = xstrdup(pf->pvar->name); 609 pf->tvar->name = strdup(pf->pvar->name);
602 else { 610 else {
603 synthesize_perf_probe_arg(pf->pvar, buf, 32); 611 ret = synthesize_perf_probe_arg(pf->pvar, buf, 32);
612 if (ret < 0)
613 return ret;
604 ptr = strchr(buf, ':'); /* Change type separator to _ */ 614 ptr = strchr(buf, ':'); /* Change type separator to _ */
605 if (ptr) 615 if (ptr)
606 *ptr = '_'; 616 *ptr = '_';
607 pf->tvar->name = xstrdup(buf); 617 pf->tvar->name = strdup(buf);
608 } 618 }
619 if (pf->tvar->name == NULL)
620 return -ENOMEM;
609 621
610 if (!is_c_varname(pf->pvar->var)) { 622 if (!is_c_varname(pf->pvar->var)) {
611 /* Copy raw parameters */ 623 /* Copy raw parameters */
612 pf->tvar->value = xstrdup(pf->pvar->var); 624 pf->tvar->value = strdup(pf->pvar->var);
613 return 0; 625 if (pf->tvar->value == NULL)
626 return -ENOMEM;
627 else
628 return 0;
614 } 629 }
615 630
616 pr_debug("Searching '%s' variable in context.\n", 631 pr_debug("Searching '%s' variable in context.\n",
@@ -660,7 +675,9 @@ static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf)
660 dwarf_diename(sp_die)); 675 dwarf_diename(sp_die));
661 return -ENOENT; 676 return -ENOENT;
662 } 677 }
663 tev->point.symbol = xstrdup(name); 678 tev->point.symbol = strdup(name);
679 if (tev->point.symbol == NULL)
680 return -ENOMEM;
664 tev->point.offset = (unsigned long)(pf->addr - eaddr); 681 tev->point.offset = (unsigned long)(pf->addr - eaddr);
665 } else 682 } else
666 /* This function has no name. */ 683 /* This function has no name. */
@@ -1028,7 +1045,11 @@ int find_perf_probe_point(int fd, unsigned long addr,
1028 tmp = dwarf_linesrc(line, NULL, NULL); 1045 tmp = dwarf_linesrc(line, NULL, NULL);
1029 if (tmp) { 1046 if (tmp) {
1030 ppt->line = lineno; 1047 ppt->line = lineno;
1031 ppt->file = xstrdup(tmp); 1048 ppt->file = strdup(tmp);
1049 if (ppt->file == NULL) {
1050 ret = -ENOMEM;
1051 goto end;
1052 }
1032 found = true; 1053 found = true;
1033 } 1054 }
1034 } 1055 }
@@ -1064,7 +1085,11 @@ int find_perf_probe_point(int fd, unsigned long addr,
1064 /* We don't have a line number, let's use offset */ 1085 /* We don't have a line number, let's use offset */
1065 ppt->offset = addr - (unsigned long)eaddr; 1086 ppt->offset = addr - (unsigned long)eaddr;
1066found: 1087found:
1067 ppt->function = xstrdup(tmp); 1088 ppt->function = strdup(tmp);
1089 if (ppt->function == NULL) {
1090 ret = -ENOMEM;
1091 goto end;
1092 }
1068 found = true; 1093 found = true;
1069 } 1094 }
1070 1095
@@ -1116,8 +1141,11 @@ static int find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf)
1116 continue; 1141 continue;
1117 1142
1118 /* Copy real path */ 1143 /* Copy real path */
1119 if (!lf->lr->path) 1144 if (!lf->lr->path) {
1120 lf->lr->path = xstrdup(src); 1145 lf->lr->path = strdup(src);
1146 if (lf->lr->path == NULL)
1147 return -ENOMEM;
1148 }
1121 line_list__add_line(&lf->lr->line_list, (unsigned int)lineno); 1149 line_list__add_line(&lf->lr->line_list, (unsigned int)lineno);
1122 } 1150 }
1123 /* Update status */ 1151 /* Update status */