Skip to content

Commit 3f136ef

Browse files
committed
trace: don't mess up pointers when we reallocate.
It's convenient to have pointers, but we have to do fixups. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 0c0345a commit 3f136ef

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

common/trace.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,28 @@ static struct span *trace_span_slot(void)
232232

233233
/* In the unlikely case this fails, double it */
234234
if (!s) {
235+
/* Adjust current and parents when we reallocate! */
236+
size_t num_active = tal_count(active_spans);
237+
size_t current_off COMPILER_WANTS_INIT("11.4.0-1ubuntu1~22.04 -03");
238+
size_t parent_off[num_active];
239+
if (current)
240+
current_off = current - active_spans;
241+
for (size_t i = 0; i < num_active; i++) {
242+
if (!active_spans[i].parent)
243+
continue;
244+
parent_off[i] = active_spans[i].parent - active_spans;
245+
}
235246
TRACE_DBG("%u: out of %zu spans, doubling!\n",
236247
getpid(), tal_count(active_spans));
237248
tal_resizez(&active_spans, tal_count(active_spans) * 2);
238249
s = trace_span_find(0);
250+
if (current)
251+
current = active_spans + current_off;
252+
for (size_t i = 0; i < num_active; i++) {
253+
if (!active_spans[i].parent)
254+
continue;
255+
active_spans[i].parent = active_spans + parent_off[i];
256+
}
239257
}
240258
assert(s->parent == NULL);
241259

0 commit comments

Comments
 (0)