aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/util/thread-stack.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c
index 03770af9e5cd..248ed3945bec 100644
--- a/tools/perf/util/thread-stack.c
+++ b/tools/perf/util/thread-stack.c
@@ -114,20 +114,25 @@ static int thread_stack__init(struct thread_stack *ts, struct thread *thread,
114static struct thread_stack *thread_stack__new(struct thread *thread, 114static struct thread_stack *thread_stack__new(struct thread *thread,
115 struct call_return_processor *crp) 115 struct call_return_processor *crp)
116{ 116{
117 struct thread_stack *ts; 117 struct thread_stack *ts = thread->ts, *new_ts;
118 118 unsigned int old_sz = ts ? ts->arr_sz : 0;
119 ts = zalloc(sizeof(struct thread_stack)); 119 unsigned int new_sz = 1;
120 if (!ts) 120
121 return NULL; 121 if (!ts || new_sz > old_sz) {
122 122 new_ts = calloc(new_sz, sizeof(*ts));
123 ts->arr_sz = 1; 123 if (!new_ts)
124 124 return NULL;
125 if (thread_stack__init(ts, thread, crp)) { 125 if (ts)
126 free(ts); 126 memcpy(new_ts, ts, old_sz * sizeof(*ts));
127 return NULL; 127 new_ts->arr_sz = new_sz;
128 zfree(&thread->ts);
129 thread->ts = new_ts;
130 ts = new_ts;
128 } 131 }
129 132
130 thread->ts = ts; 133 if (!ts->stack &&
134 thread_stack__init(ts, thread, crp))
135 return NULL;
131 136
132 return ts; 137 return ts;
133} 138}