aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/builtin-record.c5
-rw-r--r--tools/perf/util/header.c30
-rw-r--r--tools/perf/util/header.h6
3 files changed, 30 insertions, 11 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 4c03bb7a4eba..5411be4cfd77 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -221,7 +221,10 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n
221 } else { 221 } else {
222 h_attr = perf_header_attr__new(a); 222 h_attr = perf_header_attr__new(a);
223 if (h_attr != NULL) 223 if (h_attr != NULL)
224 perf_header__add_attr(header, h_attr); 224 if (perf_header__add_attr(header, h_attr) < 0) {
225 perf_header_attr__delete(h_attr);
226 h_attr = NULL;
227 }
225 } 228 }
226 229
227 return h_attr; 230 return h_attr;
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
36void perf_header_attr__delete(struct perf_header_attr *self)
37{
38 free(self->id);
39 free(self);
40}
41
36void perf_header_attr__add_id(struct perf_header_attr *self, u64 id) 42void 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
69void perf_header__add_attr(struct perf_header *self, 75int 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
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 0cbd4c9e982c..b0d5cd707a7b 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -58,13 +58,15 @@ struct perf_header {
58struct perf_header *perf_header__read(int fd); 58struct perf_header *perf_header__read(int fd);
59void perf_header__write(struct perf_header *self, int fd, bool at_exit); 59void perf_header__write(struct perf_header *self, int fd, bool at_exit);
60 60
61void perf_header__add_attr(struct perf_header *self, 61int perf_header__add_attr(struct perf_header *self,
62 struct perf_header_attr *attr); 62 struct perf_header_attr *attr);
63 63
64void perf_header__push_event(u64 id, const char *name); 64void perf_header__push_event(u64 id, const char *name);
65char *perf_header__find_event(u64 id); 65char *perf_header__find_event(u64 id);
66 66
67struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr); 67struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr);
68void perf_header_attr__delete(struct perf_header_attr *self);
69
68void perf_header_attr__add_id(struct perf_header_attr *self, u64 id); 70void perf_header_attr__add_id(struct perf_header_attr *self, u64 id);
69 71
70u64 perf_header__sample_type(struct perf_header *header); 72u64 perf_header__sample_type(struct perf_header *header);