Skip to content

Commit cde964f

Browse files
authored
Fix segfault if root task is NULL (#51471)
In `jl_print_task_backtraces()`. Follow-on to #51430.
1 parent 0a82b71 commit cde964f

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/stackwalk.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,23 +1158,30 @@ JL_DLLEXPORT void jl_print_task_backtraces(int show_done) JL_NOTSAFEPOINT
11581158
continue;
11591159
}
11601160
jl_ptls_t ptls2 = allstates[i];
1161-
if (ptls2 == NULL)
1161+
if (ptls2 == NULL) {
11621162
continue;
1163+
}
11631164
small_arraylist_t *live_tasks = &ptls2->heap.live_tasks;
11641165
size_t n = mtarraylist_length(live_tasks);
1166+
int t_state = JL_TASK_STATE_DONE;
11651167
jl_task_t *t = ptls2->root_task;
1166-
int t_state = jl_atomic_load_relaxed(&t->_state);
1168+
if (t != NULL)
1169+
t_state = jl_atomic_load_relaxed(&t->_state);
11671170
jl_safe_printf("==== Thread %d created %zu live tasks\n",
11681171
ptls2->tid + 1, n + (t_state != JL_TASK_STATE_DONE));
11691172
if (show_done || t_state != JL_TASK_STATE_DONE) {
11701173
jl_safe_printf(" ---- Root task (%p)\n", ptls2->root_task);
1171-
jl_safe_printf(" (sticky: %d, started: %d, state: %d, tid: %d)\n",
1172-
t->sticky, t->started, t_state,
1173-
jl_atomic_load_relaxed(&t->tid) + 1);
1174-
if (t->stkbuf != NULL)
1175-
jlbacktracet(t);
1176-
else
1177-
jl_safe_printf(" no stack\n");
1174+
if (t != NULL) {
1175+
jl_safe_printf(" (sticky: %d, started: %d, state: %d, tid: %d)\n",
1176+
t->sticky, t->started, t_state,
1177+
jl_atomic_load_relaxed(&t->tid) + 1);
1178+
if (t->stkbuf != NULL) {
1179+
jlbacktracet(t);
1180+
}
1181+
else {
1182+
jl_safe_printf(" no stack\n");
1183+
}
1184+
}
11781185
jl_safe_printf(" ---- End root task\n");
11791186
}
11801187

0 commit comments

Comments
 (0)