diff options
Diffstat (limited to 'tools/perf/util/header.c')
-rw-r--r-- | tools/perf/util/header.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 2f07a238ffdf..23ccddae0b06 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -33,6 +33,12 @@ struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr) | |||
33 | return self; | 33 | return self; |
34 | } | 34 | } |
35 | 35 | ||
36 | void perf_header_attr__delete(struct perf_header_attr *self) | ||
37 | { | ||
38 | free(self->id); | ||
39 | free(self); | ||
40 | } | ||
41 | |||
36 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id) | 42 | void perf_header_attr__add_id(struct perf_header_attr *self, u64 id) |
37 | { | 43 | { |
38 | int pos = self->ids; | 44 | int pos = self->ids; |
@@ -66,22 +72,28 @@ struct perf_header *perf_header__new(void) | |||
66 | return self; | 72 | return self; |
67 | } | 73 | } |
68 | 74 | ||
69 | void perf_header__add_attr(struct perf_header *self, | 75 | int perf_header__add_attr(struct perf_header *self, |
70 | struct perf_header_attr *attr) | 76 | struct perf_header_attr *attr) |
71 | { | 77 | { |
72 | int pos = self->attrs; | 78 | int pos = self->attrs; |
73 | 79 | ||
74 | if (self->frozen) | 80 | if (self->frozen) |
75 | die("frozen"); | 81 | return -1; |
76 | 82 | ||
77 | self->attrs++; | 83 | self->attrs++; |
78 | if (self->attrs > self->size) { | 84 | if (self->attrs > self->size) { |
79 | self->size *= 2; | 85 | int nsize = self->size * 2; |
80 | self->attr = realloc(self->attr, self->size * sizeof(void *)); | 86 | struct perf_header_attr **nattr; |
81 | if (!self->attr) | 87 | |
82 | die("nomem"); | 88 | nattr = realloc(self->attr, nsize * sizeof(void *)); |
89 | if (nattr == NULL) | ||
90 | return -1; | ||
91 | |||
92 | self->size = nsize; | ||
93 | self->attr = nattr; | ||
83 | } | 94 | } |
84 | self->attr[pos] = attr; | 95 | self->attr[pos] = attr; |
96 | return 0; | ||
85 | } | 97 | } |
86 | 98 | ||
87 | #define MAX_EVENT_NAME 64 | 99 | #define MAX_EVENT_NAME 64 |
@@ -434,7 +446,9 @@ struct perf_header *perf_header__read(int fd) | |||
434 | 446 | ||
435 | perf_header_attr__add_id(attr, f_id); | 447 | perf_header_attr__add_id(attr, f_id); |
436 | } | 448 | } |
437 | perf_header__add_attr(self, attr); | 449 | if (perf_header__add_attr(self, attr) < 0) |
450 | die("nomem"); | ||
451 | |||
438 | lseek(fd, tmp, SEEK_SET); | 452 | lseek(fd, tmp, SEEK_SET); |
439 | } | 453 | } |
440 | 454 | ||