From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11753 invoked by alias); 12 Apr 2010 17:11:40 -0000 Received: (qmail 11437 invoked by uid 22791); 12 Apr 2010 17:11:17 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_JL,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 12 Apr 2010 17:11:02 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3CHB0Bw006813 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 12 Apr 2010 13:11:00 -0400 Received: from localhost6.localdomain6 (dhcp-100-3-156.bos.redhat.com [10.16.3.156]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3CHAvHW024782; Mon, 12 Apr 2010 13:10:57 -0400 From: Masami Hiramatsu Subject: [PATCH -tip v3 10/10] perf probe: Remove xstrdup()/xstrndup() from util/probe-{event, finder}.c To: Ingo Molnar , Arnaldo Carvalho de Melo , lkml Cc: systemtap, DLE, Masami Hiramatsu , Ingo Molnar , Paul Mackerras , Arnaldo Carvalho de Melo , Peter Zijlstra , Mike Galbraith , Frederic Weisbecker Date: Mon, 12 Apr 2010 17:11:00 -0000 Message-ID: <20100412171756.3790.89607.stgit@localhost6.localdomain6> In-Reply-To: <20100412171646.3790.64715.stgit@localhost6.localdomain6> References: <20100412171646.3790.64715.stgit@localhost6.localdomain6> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2010-q2/txt/msg00101.txt.bz2 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. Signed-off-by: Masami Hiramatsu Cc: Ingo Molnar Cc: Paul Mackerras Cc: Arnaldo Carvalho de Melo Cc: Peter Zijlstra Cc: Mike Galbraith Cc: Frederic Weisbecker --- tools/perf/util/probe-event.c | 159 ++++++++++++++++++++++++++++------------ tools/perf/util/probe-finder.c | 58 +++++++++++---- 2 files changed, 156 insertions(+), 61 deletions(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index aacbf73..ca108b2 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -133,7 +133,9 @@ static int convert_to_perf_probe_point(struct kprobe_trace_point *tp, if (ret <= 0) { pr_debug("Failed to find corresponding probes from " "debuginfo. Use kprobe event information.\n"); - pp->function = xstrdup(tp->symbol); + pp->function = strdup(tp->symbol); + if (pp->function == NULL) + return -ENOMEM; pp->offset = tp->offset; } pp->retprobe = tp->retprobe; @@ -300,7 +302,9 @@ end: static int convert_to_perf_probe_point(struct kprobe_trace_point *tp, struct perf_probe_point *pp) { - pp->function = xstrdup(tp->symbol); + pp->function = strdup(tp->symbol); + if (pp->function == NULL) + return -ENOMEM; pp->offset = tp->offset; pp->retprobe = tp->retprobe; @@ -355,9 +359,12 @@ int parse_line_range_desc(const char *arg, struct line_range *lr) *tmp); return -EINVAL; } - tmp = xstrndup(arg, (ptr - arg)); + tmp = strndup(arg, (ptr - arg)); } else - tmp = xstrdup(arg); + tmp = strdup(arg); + + if (tmp == NULL) + return -ENOMEM; if (strchr(tmp, '.')) lr->file = tmp; @@ -406,7 +413,9 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) "follow C symbol-naming rule.\n", arg); return -EINVAL; } - pev->event = xstrdup(arg); + pev->event = strdup(arg); + if (pev->event == NULL) + return -ENOMEM; pev->group = NULL; arg = tmp; } @@ -417,18 +426,24 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) *ptr++ = '\0'; } + tmp = strdup(arg); + if (tmp == NULL) + return -ENOMEM; + /* Check arg is function or file and copy it */ - if (strchr(arg, '.')) /* File */ - pp->file = xstrdup(arg); + if (strchr(tmp, '.')) /* File */ + pp->file = tmp; else /* Function */ - pp->function = xstrdup(arg); + pp->function = tmp; /* Parse other options */ while (ptr) { arg = ptr; c = nc; if (c == ';') { /* Lazy pattern must be the last part */ - pp->lazy_line = xstrdup(arg); + pp->lazy_line = strdup(arg); + if (pp->lazy_line == NULL) + return -ENOMEM; break; } ptr = strpbrk(arg, ";:+@%"); @@ -458,7 +473,9 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) semantic_error("SRC@SRC is not allowed.\n"); return -EINVAL; } - pp->file = xstrdup(arg); + pp->file = strdup(arg); + if (pp->file == NULL) + return -ENOMEM; break; case '%': /* Probe places */ if (strcmp(arg, "return") == 0) { @@ -530,7 +547,9 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) tmp = strchr(str, '='); if (tmp) { - arg->name = xstrndup(str, tmp - str); + arg->name = strndup(str, tmp - str); + if (arg->name == NULL) + return -ENOMEM; pr_debug("name:%s ", arg->name); str = tmp + 1; } @@ -538,20 +557,26 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) tmp = strchr(str, ':'); if (tmp) { /* Type setting */ *tmp = '\0'; - arg->type = xstrdup(tmp + 1); + arg->type = strdup(tmp + 1); + if (arg->type == NULL) + return -ENOMEM; pr_debug("type:%s ", arg->type); } tmp = strpbrk(str, "-."); if (!is_c_varname(str) || !tmp) { /* A variable, register, symbol or special value */ - arg->var = xstrdup(str); + arg->var = strdup(str); + if (arg->var == NULL) + return -ENOMEM; pr_debug("%s\n", arg->var); return 0; } /* Structure fields */ - arg->var = xstrndup(str, tmp - str); + arg->var = strndup(str, tmp - str); + if (arg->var == NULL) + return -ENOMEM; pr_debug("%s, ", arg->var); fieldp = &arg->field; @@ -572,18 +597,24 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) tmp = strpbrk(str, "-."); if (tmp) { - (*fieldp)->name = xstrndup(str, tmp - str); + (*fieldp)->name = strndup(str, tmp - str); + if ((*fieldp)->name == NULL) + return -ENOMEM; pr_debug("%s(%d), ", (*fieldp)->name, (*fieldp)->ref); fieldp = &(*fieldp)->next; } } while (tmp); - (*fieldp)->name = xstrdup(str); + (*fieldp)->name = strdup(str); + if ((*fieldp)->name == NULL) + return -ENOMEM; pr_debug("%s(%d)\n", (*fieldp)->name, (*fieldp)->ref); /* If no name is specified, set the last field name */ - if (!arg->name) - arg->name = xstrdup((*fieldp)->name); - + if (!arg->name) { + arg->name = strdup((*fieldp)->name); + if (arg->name == NULL) + return -ENOMEM; + } return 0; } @@ -697,9 +728,13 @@ int parse_kprobe_trace_command(const char *cmd, struct kprobe_trace_event *tev) *p++ = '\0'; else p = argv[i + 2]; - tev->args[i].name = xstrdup(argv[i + 2]); + tev->args[i].name = strdup(argv[i + 2]); /* TODO: parse regs and offset */ - tev->args[i].value = xstrdup(p); + tev->args[i].value = strdup(p); + if (tev->args[i].name == NULL || tev->args[i].value == NULL) { + ret = -ENOMEM; + goto out; + } } ret = 0; out: @@ -933,12 +968,14 @@ error: int convert_to_perf_probe_event(struct kprobe_trace_event *tev, struct perf_probe_event *pev) { - char buf[64]; + char buf[64] = ""; int i, ret; /* Convert event/group name */ - pev->event = xstrdup(tev->event); - pev->group = xstrdup(tev->group); + pev->event = strdup(tev->event); + pev->group = strdup(tev->group); + if (pev->event == NULL || pev->group == NULL) + return -ENOMEM; /* Convert trace_point to probe_point */ ret = convert_to_perf_probe_point(&tev->point, &pev->point); @@ -950,14 +987,17 @@ int convert_to_perf_probe_event(struct kprobe_trace_event *tev, pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs); if (pev->args == NULL) return -ENOMEM; - for (i = 0; i < tev->nargs && ret >= 0; i++) + for (i = 0; i < tev->nargs && ret >= 0; i++) { if (tev->args[i].name) - pev->args[i].name = xstrdup(tev->args[i].name); + pev->args[i].name = strdup(tev->args[i].name); else { ret = synthesize_kprobe_trace_arg(&tev->args[i], buf, 64); - pev->args[i].name = xstrdup(buf); + pev->args[i].name = strdup(buf); } + if (pev->args[i].name == NULL && ret >= 0) + ret = -ENOMEM; + } if (ret < 0) clear_perf_probe_event(pev); @@ -1282,7 +1322,7 @@ static int __add_kprobe_trace_events(struct perf_probe_event *pev, ret = 0; printf("Add new event%s\n", (ntevs > 1) ? "s:" : ":"); - for (i = 0; i < ntevs && ret >= 0; i++) { + for (i = 0; i < ntevs; i++) { tev = &tevs[i]; if (pev->event) event = pev->event; @@ -1303,8 +1343,12 @@ static int __add_kprobe_trace_events(struct perf_probe_event *pev, break; event = buf; - tev->event = xstrdup(event); - tev->group = xstrdup(group); + tev->event = strdup(event); + tev->group = strdup(group); + if (tev->event == NULL || tev->group == NULL) { + ret = -ENOMEM; + break; + } ret = write_kprobe_trace_event(fd, tev); if (ret < 0) break; @@ -1360,23 +1404,40 @@ static int convert_to_kprobe_trace_events(struct perf_probe_event *pev, return -ENOMEM; /* Copy parameters */ - tev->point.symbol = xstrdup(pev->point.function); + tev->point.symbol = strdup(pev->point.function); + if (tev->point.symbol == NULL) { + ret = -ENOMEM; + goto error; + } tev->point.offset = pev->point.offset; tev->nargs = pev->nargs; if (tev->nargs) { tev->args = zalloc(sizeof(struct kprobe_trace_arg) * tev->nargs); if (tev->args == NULL) { - free(tev); - *tevs = NULL; - return -ENOMEM; + ret = -ENOMEM; + goto error; } for (i = 0; i < tev->nargs; i++) { - if (pev->args[i].name) - tev->args[i].name = xstrdup(pev->args[i].name); - tev->args[i].value = xstrdup(pev->args[i].var); - if (pev->args[i].type) - tev->args[i].type = xstrdup(pev->args[i].type); + if (pev->args[i].name) { + tev->args[i].name = strdup(pev->args[i].name); + if (tev->args[i].name == NULL) { + ret = -ENOMEM; + goto error; + } + } + tev->args[i].value = strdup(pev->args[i].var); + if (tev->args[i].value == NULL) { + ret = -ENOMEM; + goto error; + } + if (pev->args[i].type) { + tev->args[i].type = strdup(pev->args[i].type); + if (tev->args[i].type == NULL) { + ret = -ENOMEM; + goto error; + } + } } } @@ -1386,13 +1447,15 @@ static int convert_to_kprobe_trace_events(struct perf_probe_event *pev, if (!sym) { pr_warning("Kernel symbol \'%s\' not found.\n", tev->point.symbol); - clear_kprobe_trace_event(tev); - free(tev); - *tevs = NULL; - return -ENOENT; - } else - ret = 1; + ret = -ENOENT; + goto error; + } + return 1; +error: + clear_kprobe_trace_event(tev); + free(tev); + *tevs = NULL; return ret; } @@ -1528,7 +1591,11 @@ int del_perf_probe_events(struct strlist *dellist) return -EINVAL; strlist__for_each(ent, dellist) { - str = xstrdup(ent->s); + str = strdup(ent->s); + if (str == NULL) { + ret = -ENOMEM; + break; + } pr_debug("Parsing: %s\n", str); p = strchr(str, ':'); if (p) { diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index ce1ac82..e443e69 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) return -ERANGE; } - tvar->value = xstrdup(regs); + tvar->value = strdup(regs); + if (tvar->value == NULL) + return -ENOMEM; + if (ref) { tvar->ref = zalloc(sizeof(struct kprobe_trace_arg_ref)); if (tvar->ref == NULL) @@ -466,7 +469,9 @@ static int convert_variable_type(Dwarf_Die *vr_die, strerror(-ret)); return ret; } - targ->type = xstrdup(buf); + targ->type = strdup(buf); + if (targ->type == NULL) + return -ENOMEM; } return 0; } @@ -576,9 +581,11 @@ static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf) vr_die = &die_mem; } if (ret == 0) { - if (pf->pvar->type) - pf->tvar->type = xstrdup(pf->pvar->type); - else + if (pf->pvar->type) { + pf->tvar->type = strdup(pf->pvar->type); + if (pf->tvar->type == NULL) + ret = -ENOMEM; + } else ret = convert_variable_type(vr_die, pf->tvar); } /* *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) { Dwarf_Die vr_die; char buf[32], *ptr; + int ret; /* TODO: Support arrays */ if (pf->pvar->name) - pf->tvar->name = xstrdup(pf->pvar->name); + pf->tvar->name = strdup(pf->pvar->name); else { - synthesize_perf_probe_arg(pf->pvar, buf, 32); + ret = synthesize_perf_probe_arg(pf->pvar, buf, 32); + if (ret < 0) + return ret; ptr = strchr(buf, ':'); /* Change type separator to _ */ if (ptr) *ptr = '_'; - pf->tvar->name = xstrdup(buf); + pf->tvar->name = strdup(buf); } + if (pf->tvar->name == NULL) + return -ENOMEM; if (!is_c_varname(pf->pvar->var)) { /* Copy raw parameters */ - pf->tvar->value = xstrdup(pf->pvar->var); - return 0; + pf->tvar->value = strdup(pf->pvar->var); + if (pf->tvar->value == NULL) + return -ENOMEM; + else + return 0; } 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) dwarf_diename(sp_die)); return -ENOENT; } - tev->point.symbol = xstrdup(name); + tev->point.symbol = strdup(name); + if (tev->point.symbol == NULL) + return -ENOMEM; tev->point.offset = (unsigned long)(pf->addr - eaddr); } else /* This function has no name. */ @@ -1028,7 +1045,11 @@ int find_perf_probe_point(int fd, unsigned long addr, tmp = dwarf_linesrc(line, NULL, NULL); if (tmp) { ppt->line = lineno; - ppt->file = xstrdup(tmp); + ppt->file = strdup(tmp); + if (ppt->file == NULL) { + ret = -ENOMEM; + goto end; + } found = true; } } @@ -1064,7 +1085,11 @@ int find_perf_probe_point(int fd, unsigned long addr, /* We don't have a line number, let's use offset */ ppt->offset = addr - (unsigned long)eaddr; found: - ppt->function = xstrdup(tmp); + ppt->function = strdup(tmp); + if (ppt->function == NULL) { + ret = -ENOMEM; + goto end; + } found = true; } @@ -1116,8 +1141,11 @@ static int find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf) continue; /* Copy real path */ - if (!lf->lr->path) - lf->lr->path = xstrdup(src); + if (!lf->lr->path) { + lf->lr->path = strdup(src); + if (lf->lr->path == NULL) + return -ENOMEM; + } line_list__add_line(&lf->lr->line_list, (unsigned int)lineno); } /* Update status */ -- Masami Hiramatsu e-mail: mhiramat@redhat.com From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32005 invoked by alias); 14 Apr 2010 08:36:52 -0000 Received: (qmail 31995 invoked by uid 22791); 14 Apr 2010 08:36:50 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=BAYES_00,SPF_FAIL,TW_JL X-Spam-Check-By: sourceware.org Received: from paste.autodesk.com (HELO paste.autodesk.com) (198.102.112.48) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 14 Apr 2010 08:36:40 +0000 Received: from smtp.mgd.autodesk.com ([65.54.1.156]) by paste.autodesk.com (8.14.1/8.12.6) with ESMTP id o3E8aaXD023246 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Wed, 14 Apr 2010 01:36:39 -0700 (PDT) Received: from replay.MGDADSK.autodesk.com (65.54.1.157) by ADSK-TK5MHUB-01.mgdadsk.autodesk.com (65.54.1.156) with Microsoft SMTP Server id 8.2.213.0; Wed, 14 Apr 2010 00:45:11 -0700 Received: from mail pickup service by replay.MGDADSK.autodesk.com with Microsoft SMTPSVC; Wed, 14 Apr 2010 00:45:11 -0700 Received: from paste.autodesk.com (144.111.39.111) by ADSK-TK5MHUB-01.mgdadsk.autodesk.com (65.54.1.156) with Microsoft SMTP Server id 8.2.213.0; Mon, 12 Apr 2010 10:15:16 -0700 Received: from mail142.messagelabs.com (mail142.messagelabs.com [216.82.249.99]) by paste.autodesk.com (8.14.1/8.12.6) with SMTP id o3CHFFP4000964 for ; Mon, 12 Apr 2010 10:15:15 -0700 (PDT) X-VirusChecked: Checked X-Env-Sender: linux-kernel-owner@vger.kernel.org X-Msg-Ref: server-7.tower-142.messagelabs.com!1271092493!58841064!10 X-StarScan-Version: 6.2.4; banners=-,-,- X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMjA5LjEzMi4xODAuNjcgPT4gOTQ0OTU=\n Received: (qmail 4690 invoked from network); 12 Apr 2010 17:15:08 -0000 Received: from vger.kernel.org (HELO vger.kernel.org) (209.132.180.67) by server-7.tower-142.messagelabs.com with SMTP; 12 Apr 2010 17:15:08 -0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753561Ab0DLRLW (ORCPT ); Mon, 12 Apr 2010 13:11:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9876 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753526Ab0DLRLV (ORCPT ); Mon, 12 Apr 2010 13:11:21 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3CHB04I005206 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 12 Apr 2010 13:11:00 -0400 Received: from localhost6.localdomain6 (dhcp-100-3-156.bos.redhat.com [10.16.3.156]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3CHAvHW024782; Mon, 12 Apr 2010 13:10:57 -0400 From: Masami Hiramatsu Subject: [PATCH -tip v3 10/10] perf probe: Remove xstrdup()/xstrndup() from util/probe-{event, finder}.c To: Ingo Molnar , Arnaldo Carvalho de Melo , lkml CC: systemtap , DLE , Masami Hiramatsu , Ingo Molnar , Paul Mackerras , Arnaldo Carvalho de Melo , Peter Zijlstra , Mike Galbraith , Frederic Weisbecker Date: Wed, 14 Apr 2010 22:30:00 -0000 Message-ID: <20100412171756.3790.89607.stgit@localhost6.localdomain6> In-Reply-To: <20100412171646.3790.64715.stgit@localhost6.localdomain6> References: <20100412171646.3790.64715.stgit@localhost6.localdomain6> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Mailing-List: linux-kernel@vger.kernel.org X-IsSubscribed: yes Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2010-q2/txt/msg00120.txt.bz2 Message-ID: <20100414223000.Kbiwh9c5KlzoGlOLrBeKcIx9ZqSXVO1ej9FkiHPNYDE@z> 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. Signed-off-by: Masami Hiramatsu Cc: Ingo Molnar Cc: Paul Mackerras Cc: Arnaldo Carvalho de Melo Cc: Peter Zijlstra Cc: Mike Galbraith Cc: Frederic Weisbecker --- tools/perf/util/probe-event.c | 159 ++++++++++++++++++++++++++++------------ tools/perf/util/probe-finder.c | 58 +++++++++++---- 2 files changed, 156 insertions(+), 61 deletions(-) diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index aacbf73..ca108b2 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -133,7 +133,9 @@ static int convert_to_perf_probe_point(struct kprobe_trace_point *tp, if (ret <= 0) { pr_debug("Failed to find corresponding probes from " "debuginfo. Use kprobe event information.\n"); - pp->function = xstrdup(tp->symbol); + pp->function = strdup(tp->symbol); + if (pp->function == NULL) + return -ENOMEM; pp->offset = tp->offset; } pp->retprobe = tp->retprobe; @@ -300,7 +302,9 @@ end: static int convert_to_perf_probe_point(struct kprobe_trace_point *tp, struct perf_probe_point *pp) { - pp->function = xstrdup(tp->symbol); + pp->function = strdup(tp->symbol); + if (pp->function == NULL) + return -ENOMEM; pp->offset = tp->offset; pp->retprobe = tp->retprobe; @@ -355,9 +359,12 @@ int parse_line_range_desc(const char *arg, struct line_range *lr) *tmp); return -EINVAL; } - tmp = xstrndup(arg, (ptr - arg)); + tmp = strndup(arg, (ptr - arg)); } else - tmp = xstrdup(arg); + tmp = strdup(arg); + + if (tmp == NULL) + return -ENOMEM; if (strchr(tmp, '.')) lr->file = tmp; @@ -406,7 +413,9 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) "follow C symbol-naming rule.\n", arg); return -EINVAL; } - pev->event = xstrdup(arg); + pev->event = strdup(arg); + if (pev->event == NULL) + return -ENOMEM; pev->group = NULL; arg = tmp; } @@ -417,18 +426,24 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) *ptr++ = '\0'; } + tmp = strdup(arg); + if (tmp == NULL) + return -ENOMEM; + /* Check arg is function or file and copy it */ - if (strchr(arg, '.')) /* File */ - pp->file = xstrdup(arg); + if (strchr(tmp, '.')) /* File */ + pp->file = tmp; else /* Function */ - pp->function = xstrdup(arg); + pp->function = tmp; /* Parse other options */ while (ptr) { arg = ptr; c = nc; if (c == ';') { /* Lazy pattern must be the last part */ - pp->lazy_line = xstrdup(arg); + pp->lazy_line = strdup(arg); + if (pp->lazy_line == NULL) + return -ENOMEM; break; } ptr = strpbrk(arg, ";:+@%"); @@ -458,7 +473,9 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) semantic_error("SRC@SRC is not allowed.\n"); return -EINVAL; } - pp->file = xstrdup(arg); + pp->file = strdup(arg); + if (pp->file == NULL) + return -ENOMEM; break; case '%': /* Probe places */ if (strcmp(arg, "return") == 0) { @@ -530,7 +547,9 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) tmp = strchr(str, '='); if (tmp) { - arg->name = xstrndup(str, tmp - str); + arg->name = strndup(str, tmp - str); + if (arg->name == NULL) + return -ENOMEM; pr_debug("name:%s ", arg->name); str = tmp + 1; } @@ -538,20 +557,26 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) tmp = strchr(str, ':'); if (tmp) { /* Type setting */ *tmp = '\0'; - arg->type = xstrdup(tmp + 1); + arg->type = strdup(tmp + 1); + if (arg->type == NULL) + return -ENOMEM; pr_debug("type:%s ", arg->type); } tmp = strpbrk(str, "-."); if (!is_c_varname(str) || !tmp) { /* A variable, register, symbol or special value */ - arg->var = xstrdup(str); + arg->var = strdup(str); + if (arg->var == NULL) + return -ENOMEM; pr_debug("%s\n", arg->var); return 0; } /* Structure fields */ - arg->var = xstrndup(str, tmp - str); + arg->var = strndup(str, tmp - str); + if (arg->var == NULL) + return -ENOMEM; pr_debug("%s, ", arg->var); fieldp = &arg->field; @@ -572,18 +597,24 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) tmp = strpbrk(str, "-."); if (tmp) { - (*fieldp)->name = xstrndup(str, tmp - str); + (*fieldp)->name = strndup(str, tmp - str); + if ((*fieldp)->name == NULL) + return -ENOMEM; pr_debug("%s(%d), ", (*fieldp)->name, (*fieldp)->ref); fieldp = &(*fieldp)->next; } } while (tmp); - (*fieldp)->name = xstrdup(str); + (*fieldp)->name = strdup(str); + if ((*fieldp)->name == NULL) + return -ENOMEM; pr_debug("%s(%d)\n", (*fieldp)->name, (*fieldp)->ref); /* If no name is specified, set the last field name */ - if (!arg->name) - arg->name = xstrdup((*fieldp)->name); - + if (!arg->name) { + arg->name = strdup((*fieldp)->name); + if (arg->name == NULL) + return -ENOMEM; + } return 0; } @@ -697,9 +728,13 @@ int parse_kprobe_trace_command(const char *cmd, struct kprobe_trace_event *tev) *p++ = '\0'; else p = argv[i + 2]; - tev->args[i].name = xstrdup(argv[i + 2]); + tev->args[i].name = strdup(argv[i + 2]); /* TODO: parse regs and offset */ - tev->args[i].value = xstrdup(p); + tev->args[i].value = strdup(p); + if (tev->args[i].name == NULL || tev->args[i].value == NULL) { + ret = -ENOMEM; + goto out; + } } ret = 0; out: @@ -933,12 +968,14 @@ error: int convert_to_perf_probe_event(struct kprobe_trace_event *tev, struct perf_probe_event *pev) { - char buf[64]; + char buf[64] = ""; int i, ret; /* Convert event/group name */ - pev->event = xstrdup(tev->event); - pev->group = xstrdup(tev->group); + pev->event = strdup(tev->event); + pev->group = strdup(tev->group); + if (pev->event == NULL || pev->group == NULL) + return -ENOMEM; /* Convert trace_point to probe_point */ ret = convert_to_perf_probe_point(&tev->point, &pev->point); @@ -950,14 +987,17 @@ int convert_to_perf_probe_event(struct kprobe_trace_event *tev, pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs); if (pev->args == NULL) return -ENOMEM; - for (i = 0; i < tev->nargs && ret >= 0; i++) + for (i = 0; i < tev->nargs && ret >= 0; i++) { if (tev->args[i].name) - pev->args[i].name = xstrdup(tev->args[i].name); + pev->args[i].name = strdup(tev->args[i].name); else { ret = synthesize_kprobe_trace_arg(&tev->args[i], buf, 64); - pev->args[i].name = xstrdup(buf); + pev->args[i].name = strdup(buf); } + if (pev->args[i].name == NULL && ret >= 0) + ret = -ENOMEM; + } if (ret < 0) clear_perf_probe_event(pev); @@ -1282,7 +1322,7 @@ static int __add_kprobe_trace_events(struct perf_probe_event *pev, ret = 0; printf("Add new event%s\n", (ntevs > 1) ? "s:" : ":"); - for (i = 0; i < ntevs && ret >= 0; i++) { + for (i = 0; i < ntevs; i++) { tev = &tevs[i]; if (pev->event) event = pev->event; @@ -1303,8 +1343,12 @@ static int __add_kprobe_trace_events(struct perf_probe_event *pev, break; event = buf; - tev->event = xstrdup(event); - tev->group = xstrdup(group); + tev->event = strdup(event); + tev->group = strdup(group); + if (tev->event == NULL || tev->group == NULL) { + ret = -ENOMEM; + break; + } ret = write_kprobe_trace_event(fd, tev); if (ret < 0) break; @@ -1360,23 +1404,40 @@ static int convert_to_kprobe_trace_events(struct perf_probe_event *pev, return -ENOMEM; /* Copy parameters */ - tev->point.symbol = xstrdup(pev->point.function); + tev->point.symbol = strdup(pev->point.function); + if (tev->point.symbol == NULL) { + ret = -ENOMEM; + goto error; + } tev->point.offset = pev->point.offset; tev->nargs = pev->nargs; if (tev->nargs) { tev->args = zalloc(sizeof(struct kprobe_trace_arg) * tev->nargs); if (tev->args == NULL) { - free(tev); - *tevs = NULL; - return -ENOMEM; + ret = -ENOMEM; + goto error; } for (i = 0; i < tev->nargs; i++) { - if (pev->args[i].name) - tev->args[i].name = xstrdup(pev->args[i].name); - tev->args[i].value = xstrdup(pev->args[i].var); - if (pev->args[i].type) - tev->args[i].type = xstrdup(pev->args[i].type); + if (pev->args[i].name) { + tev->args[i].name = strdup(pev->args[i].name); + if (tev->args[i].name == NULL) { + ret = -ENOMEM; + goto error; + } + } + tev->args[i].value = strdup(pev->args[i].var); + if (tev->args[i].value == NULL) { + ret = -ENOMEM; + goto error; + } + if (pev->args[i].type) { + tev->args[i].type = strdup(pev->args[i].type); + if (tev->args[i].type == NULL) { + ret = -ENOMEM; + goto error; + } + } } } @@ -1386,13 +1447,15 @@ static int convert_to_kprobe_trace_events(struct perf_probe_event *pev, if (!sym) { pr_warning("Kernel symbol \'%s\' not found.\n", tev->point.symbol); - clear_kprobe_trace_event(tev); - free(tev); - *tevs = NULL; - return -ENOENT; - } else - ret = 1; + ret = -ENOENT; + goto error; + } + return 1; +error: + clear_kprobe_trace_event(tev); + free(tev); + *tevs = NULL; return ret; } @@ -1528,7 +1591,11 @@ int del_perf_probe_events(struct strlist *dellist) return -EINVAL; strlist__for_each(ent, dellist) { - str = xstrdup(ent->s); + str = strdup(ent->s); + if (str == NULL) { + ret = -ENOMEM; + break; + } pr_debug("Parsing: %s\n", str); p = strchr(str, ':'); if (p) { diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index ce1ac82..e443e69 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) return -ERANGE; } - tvar->value = xstrdup(regs); + tvar->value = strdup(regs); + if (tvar->value == NULL) + return -ENOMEM; + if (ref) { tvar->ref = zalloc(sizeof(struct kprobe_trace_arg_ref)); if (tvar->ref == NULL) @@ -466,7 +469,9 @@ static int convert_variable_type(Dwarf_Die *vr_die, strerror(-ret)); return ret; } - targ->type = xstrdup(buf); + targ->type = strdup(buf); + if (targ->type == NULL) + return -ENOMEM; } return 0; } @@ -576,9 +581,11 @@ static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf) vr_die = &die_mem; } if (ret == 0) { - if (pf->pvar->type) - pf->tvar->type = xstrdup(pf->pvar->type); - else + if (pf->pvar->type) { + pf->tvar->type = strdup(pf->pvar->type); + if (pf->tvar->type == NULL) + ret = -ENOMEM; + } else ret = convert_variable_type(vr_die, pf->tvar); } /* *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) { Dwarf_Die vr_die; char buf[32], *ptr; + int ret; /* TODO: Support arrays */ if (pf->pvar->name) - pf->tvar->name = xstrdup(pf->pvar->name); + pf->tvar->name = strdup(pf->pvar->name); else { - synthesize_perf_probe_arg(pf->pvar, buf, 32); + ret = synthesize_perf_probe_arg(pf->pvar, buf, 32); + if (ret < 0) + return ret; ptr = strchr(buf, ':'); /* Change type separator to _ */ if (ptr) *ptr = '_'; - pf->tvar->name = xstrdup(buf); + pf->tvar->name = strdup(buf); } + if (pf->tvar->name == NULL) + return -ENOMEM; if (!is_c_varname(pf->pvar->var)) { /* Copy raw parameters */ - pf->tvar->value = xstrdup(pf->pvar->var); - return 0; + pf->tvar->value = strdup(pf->pvar->var); + if (pf->tvar->value == NULL) + return -ENOMEM; + else + return 0; } 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) dwarf_diename(sp_die)); return -ENOENT; } - tev->point.symbol = xstrdup(name); + tev->point.symbol = strdup(name); + if (tev->point.symbol == NULL) + return -ENOMEM; tev->point.offset = (unsigned long)(pf->addr - eaddr); } else /* This function has no name. */ @@ -1028,7 +1045,11 @@ int find_perf_probe_point(int fd, unsigned long addr, tmp = dwarf_linesrc(line, NULL, NULL); if (tmp) { ppt->line = lineno; - ppt->file = xstrdup(tmp); + ppt->file = strdup(tmp); + if (ppt->file == NULL) { + ret = -ENOMEM; + goto end; + } found = true; } } @@ -1064,7 +1085,11 @@ int find_perf_probe_point(int fd, unsigned long addr, /* We don't have a line number, let's use offset */ ppt->offset = addr - (unsigned long)eaddr; found: - ppt->function = xstrdup(tmp); + ppt->function = strdup(tmp); + if (ppt->function == NULL) { + ret = -ENOMEM; + goto end; + } found = true; } @@ -1116,8 +1141,11 @@ static int find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf) continue; /* Copy real path */ - if (!lf->lr->path) - lf->lr->path = xstrdup(src); + if (!lf->lr->path) { + lf->lr->path = strdup(src); + if (lf->lr->path == NULL) + return -ENOMEM; + } line_list__add_line(&lf->lr->line_list, (unsigned int)lineno); } /* Update status */ -- Masami Hiramatsu e-mail: mhiramat@redhat.com -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/