Skip to content

Commit 5b03266

Browse files
committed
Foolproof coroutine_init and coroutine_finish
1 parent 9a314bf commit 5b03266

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

coroutine.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,14 @@ void coroutine_switch_context(void *rsp, Sleep_Mode sm, int fd)
200200

201201
void coroutine_init(void)
202202
{
203+
if (contexts.count != 0) return;
203204
da_append(&contexts, (Context){0});
204205
da_append(&active, 0);
205206
}
206207

207208
void coroutine_finish(void)
208209
{
210+
if (contexts.count == 0) return;
209211
if (active.items[current] == 0) {
210212
for (size_t i = 1; i < contexts.count; ++i) {
211213
free(contexts.items[i].stack_base);

0 commit comments

Comments
 (0)