MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

destroy coro->vm only when reaped

+30 -20
+30 -20
src/sugar.c
··· 91 91 retired_coroutines = coro; 92 92 } 93 93 94 + static void destroy_coroutine_resources(coroutine_t *coro) { 95 + if (!coro) return; 96 + 97 + if (coro->mco) { 98 + void *ctx = mco_get_user_data(coro->mco); 99 + if (ctx) CORO_FREE(ctx); 100 + mco_destroy(coro->mco); 101 + coro->mco = NULL; 102 + } 103 + 104 + if (coro->args) { 105 + CORO_FREE(coro->args); 106 + coro->args = NULL; 107 + } 108 + 109 + if (coro->sv_vm) { 110 + sv_vm_destroy(coro->sv_vm); 111 + coro->sv_vm = NULL; 112 + } 113 + 114 + coro->js = NULL; 115 + coro->active_parent = NULL; 116 + } 117 + 94 118 void reap_retired_coroutines(void) { 95 119 coroutine_t *coro = retired_coroutines; 96 120 retired_coroutines = NULL; 121 + 97 122 while (coro) { 98 123 coroutine_t *next = coro->next; 124 + destroy_coroutine_resources(coro); 99 125 CORO_FREE(coro); 100 126 coro = next; 101 127 } ··· 120 146 if (js->active_async_coro == coro) js->active_async_coro = coro->active_parent; 121 147 coro->active_parent = NULL; 122 148 } 123 - 124 - if (coro->mco) { 125 - void *ctx = mco_get_user_data(coro->mco); 126 - if (ctx) CORO_FREE(ctx); 127 - mco_destroy(coro->mco); 128 - coro->mco = NULL; 129 - } 130 - 131 - if (coro->args) { 132 - CORO_FREE(coro->args); 133 - coro->args = NULL; 134 - } 135 - 136 - if (coro->sv_vm) { 137 - sv_vm_destroy(coro->sv_vm); 138 - coro->sv_vm = NULL; 139 - } 140 - 141 - coro->js = NULL; 142 - coro->active_parent = NULL; 149 + 150 + if (!js || js->vm_exec_depth == 0) 151 + destroy_coroutine_resources(coro); 152 + 143 153 retire_coroutine_storage(coro); 144 154 } 145 155