aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/header.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-11-16 22:18:09 -0500
committerIngo Molnar <mingo@elte.hu>2009-11-17 01:19:54 -0500
commit11deb1f9f6ca6318fa9470e024b9f0634df48b4c (patch)
tree3f1e18ccaffa47e1a139c1f2f12f94510c3a4751 /tools/perf/util/header.c
parent1124ba73be6a758965340bd997593b2996649d60 (diff)
perf tools: Don't die() in perf_header__add_attr()
Propagate the errors instead, the users are the ones to decide what to do if a library call fails. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> LKML-Reference: <1258427892-16312-1-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/header.c')
-rw-r--r--tools/perf/util/header.c30
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
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