diff options
| -rw-r--r-- | tools/perf/builtin-record.c | 5 | ||||
| -rw-r--r-- | tools/perf/util/header.c | 18 | ||||
| -rw-r--r-- | tools/perf/util/header.h | 2 |
3 files changed, 17 insertions, 8 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 5411be4cfd77..2a85205ba01a 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
| @@ -327,7 +327,10 @@ try_again: | |||
| 327 | exit(-1); | 327 | exit(-1); |
| 328 | } | 328 | } |
| 329 | 329 | ||
| 330 | perf_header_attr__add_id(h_attr, read_data.id); | 330 | if (perf_header_attr__add_id(h_attr, read_data.id) < 0) { |
| 331 | pr_warning("Not enough memory to add id\n"); | ||
| 332 | exit(-1); | ||
| 333 | } | ||
| 331 | 334 | ||
| 332 | assert(fd[nr_cpu][counter] >= 0); | 335 | assert(fd[nr_cpu][counter] >= 0); |
| 333 | fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK); | 336 | fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK); |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 23ccddae0b06..dee1ed2f0d1b 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
| @@ -39,18 +39,23 @@ void perf_header_attr__delete(struct perf_header_attr *self) | |||
| 39 | free(self); | 39 | free(self); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id) | 42 | int perf_header_attr__add_id(struct perf_header_attr *self, u64 id) |
| 43 | { | 43 | { |
| 44 | int pos = self->ids; | 44 | int pos = self->ids; |
| 45 | 45 | ||
| 46 | self->ids++; | 46 | self->ids++; |
| 47 | if (self->ids > self->size) { | 47 | if (self->ids > self->size) { |
| 48 | self->size *= 2; | 48 | int nsize = self->size * 2; |
| 49 | self->id = realloc(self->id, self->size * sizeof(u64)); | 49 | u64 *nid = realloc(self->id, nsize * sizeof(u64)); |
| 50 | if (!self->id) | 50 | |
| 51 | die("nomem"); | 51 | if (nid == NULL) |
| 52 | return -1; | ||
| 53 | |||
| 54 | self->size = nsize; | ||
| 55 | self->id = nid; | ||
| 52 | } | 56 | } |
| 53 | self->id[pos] = id; | 57 | self->id[pos] = id; |
| 58 | return 0; | ||
| 54 | } | 59 | } |
| 55 | 60 | ||
| 56 | /* | 61 | /* |
| @@ -444,7 +449,8 @@ struct perf_header *perf_header__read(int fd) | |||
| 444 | for (j = 0; j < nr_ids; j++) { | 449 | for (j = 0; j < nr_ids; j++) { |
| 445 | do_read(fd, &f_id, sizeof(f_id)); | 450 | do_read(fd, &f_id, sizeof(f_id)); |
| 446 | 451 | ||
| 447 | perf_header_attr__add_id(attr, f_id); | 452 | if (perf_header_attr__add_id(attr, f_id) < 0) |
| 453 | die("nomem"); | ||
| 448 | } | 454 | } |
| 449 | if (perf_header__add_attr(self, attr) < 0) | 455 | if (perf_header__add_attr(self, attr) < 0) |
| 450 | die("nomem"); | 456 | die("nomem"); |
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index b0d5cd707a7b..f46a94e09eea 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h | |||
| @@ -67,7 +67,7 @@ char *perf_header__find_event(u64 id); | |||
| 67 | struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr); | 67 | struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr); |
| 68 | void perf_header_attr__delete(struct perf_header_attr *self); | 68 | void perf_header_attr__delete(struct perf_header_attr *self); |
| 69 | 69 | ||
| 70 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id); | 70 | int perf_header_attr__add_id(struct perf_header_attr *self, u64 id); |
| 71 | 71 | ||
| 72 | u64 perf_header__sample_type(struct perf_header *header); | 72 | u64 perf_header__sample_type(struct perf_header *header); |
| 73 | struct perf_event_attr * | 73 | struct perf_event_attr * |
