|
@@ -556,7 +556,9 @@ static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg)
|
|
|
fieldp = &arg->field;
|
|
|
|
|
|
do {
|
|
|
- *fieldp = xzalloc(sizeof(struct perf_probe_arg_field));
|
|
|
+ *fieldp = zalloc(sizeof(struct perf_probe_arg_field));
|
|
|
+ if (*fieldp == NULL)
|
|
|
+ return -ENOMEM;
|
|
|
if (*tmp == '.') {
|
|
|
str = tmp + 1;
|
|
|
(*fieldp)->ref = false;
|
|
@@ -608,7 +610,11 @@ int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev)
|
|
|
|
|
|
/* Copy arguments and ensure return probe has no C argument */
|
|
|
pev->nargs = argc - 1;
|
|
|
- pev->args = xzalloc(sizeof(struct perf_probe_arg) * pev->nargs);
|
|
|
+ pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs);
|
|
|
+ if (pev->args == NULL) {
|
|
|
+ ret = -ENOMEM;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
for (i = 0; i < pev->nargs && ret >= 0; i++) {
|
|
|
ret = parse_perf_probe_arg(argv[i + 1], &pev->args[i]);
|
|
|
if (ret >= 0 &&
|
|
@@ -680,7 +686,11 @@ int parse_kprobe_trace_command(const char *cmd, struct kprobe_trace_event *tev)
|
|
|
tp->offset = 0;
|
|
|
|
|
|
tev->nargs = argc - 2;
|
|
|
- tev->args = xzalloc(sizeof(struct kprobe_trace_arg) * tev->nargs);
|
|
|
+ tev->args = zalloc(sizeof(struct kprobe_trace_arg) * tev->nargs);
|
|
|
+ if (tev->args == NULL) {
|
|
|
+ ret = -ENOMEM;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
for (i = 0; i < tev->nargs; i++) {
|
|
|
p = strchr(argv[i + 2], '=');
|
|
|
if (p) /* We don't need which register is assigned. */
|
|
@@ -745,7 +755,11 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
|
|
|
char offs[32] = "", line[32] = "", file[32] = "";
|
|
|
int ret, len;
|
|
|
|
|
|
- buf = xzalloc(MAX_CMDLEN);
|
|
|
+ buf = zalloc(MAX_CMDLEN);
|
|
|
+ if (buf == NULL) {
|
|
|
+ ret = -ENOMEM;
|
|
|
+ goto error;
|
|
|
+ }
|
|
|
if (pp->offset) {
|
|
|
ret = e_snprintf(offs, 32, "+%lu", pp->offset);
|
|
|
if (ret <= 0)
|
|
@@ -781,7 +795,8 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
|
|
|
error:
|
|
|
pr_debug("Failed to synthesize perf probe point: %s",
|
|
|
strerror(-ret));
|
|
|
- free(buf);
|
|
|
+ if (buf)
|
|
|
+ free(buf);
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
@@ -890,7 +905,10 @@ char *synthesize_kprobe_trace_command(struct kprobe_trace_event *tev)
|
|
|
char *buf;
|
|
|
int i, len, ret;
|
|
|
|
|
|
- buf = xzalloc(MAX_CMDLEN);
|
|
|
+ buf = zalloc(MAX_CMDLEN);
|
|
|
+ if (buf == NULL)
|
|
|
+ return NULL;
|
|
|
+
|
|
|
len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s+%lu",
|
|
|
tp->retprobe ? 'r' : 'p',
|
|
|
tev->group, tev->event,
|
|
@@ -929,7 +947,9 @@ int convert_to_perf_probe_event(struct kprobe_trace_event *tev,
|
|
|
|
|
|
/* Convert trace_arg to probe_arg */
|
|
|
pev->nargs = tev->nargs;
|
|
|
- pev->args = xzalloc(sizeof(struct perf_probe_arg) * pev->nargs);
|
|
|
+ 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++)
|
|
|
if (tev->args[i].name)
|
|
|
pev->args[i].name = xstrdup(tev->args[i].name);
|
|
@@ -1326,25 +1346,31 @@ static int convert_to_kprobe_trace_events(struct perf_probe_event *pev,
|
|
|
struct kprobe_trace_event **tevs)
|
|
|
{
|
|
|
struct symbol *sym;
|
|
|
- int ntevs = 0, i;
|
|
|
+ int ret = 0, i;
|
|
|
struct kprobe_trace_event *tev;
|
|
|
|
|
|
/* Convert perf_probe_event with debuginfo */
|
|
|
- ntevs = try_to_find_kprobe_trace_events(pev, tevs);
|
|
|
- if (ntevs != 0)
|
|
|
- return ntevs;
|
|
|
+ ret = try_to_find_kprobe_trace_events(pev, tevs);
|
|
|
+ if (ret != 0)
|
|
|
+ return ret;
|
|
|
|
|
|
/* Allocate trace event buffer */
|
|
|
- ntevs = 1;
|
|
|
- tev = *tevs = xzalloc(sizeof(struct kprobe_trace_event));
|
|
|
+ tev = *tevs = zalloc(sizeof(struct kprobe_trace_event));
|
|
|
+ if (tev == NULL)
|
|
|
+ return -ENOMEM;
|
|
|
|
|
|
/* Copy parameters */
|
|
|
tev->point.symbol = xstrdup(pev->point.function);
|
|
|
tev->point.offset = pev->point.offset;
|
|
|
tev->nargs = pev->nargs;
|
|
|
if (tev->nargs) {
|
|
|
- tev->args = xzalloc(sizeof(struct kprobe_trace_arg)
|
|
|
- * tev->nargs);
|
|
|
+ tev->args = zalloc(sizeof(struct kprobe_trace_arg)
|
|
|
+ * tev->nargs);
|
|
|
+ if (tev->args == NULL) {
|
|
|
+ free(tev);
|
|
|
+ *tevs = NULL;
|
|
|
+ return -ENOMEM;
|
|
|
+ }
|
|
|
for (i = 0; i < tev->nargs; i++) {
|
|
|
if (pev->args[i].name)
|
|
|
tev->args[i].name = xstrdup(pev->args[i].name);
|
|
@@ -1360,9 +1386,14 @@ 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;
|
|
|
- }
|
|
|
- return ntevs;
|
|
|
+ } else
|
|
|
+ ret = 1;
|
|
|
+
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
struct __event_package {
|
|
@@ -1377,7 +1408,9 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
|
|
|
int i, j, ret;
|
|
|
struct __event_package *pkgs;
|
|
|
|
|
|
- pkgs = xzalloc(sizeof(struct __event_package) * npevs);
|
|
|
+ pkgs = zalloc(sizeof(struct __event_package) * npevs);
|
|
|
+ if (pkgs == NULL)
|
|
|
+ return -ENOMEM;
|
|
|
|
|
|
/* Init vmlinux path */
|
|
|
ret = init_vmlinux();
|