@@ -188,22 +188,8 @@ COLD_FUNC void globalcontext_destroy(GlobalContext *glb)
188188{
189189 sys_free_platform (glb );
190190
191- #ifndef AVM_NO_SMP
192- smp_condvar_destroy (glb -> schedulers_cv );
193- smp_mutex_destroy (glb -> schedulers_mutex );
194- smp_rwlock_destroy (glb -> modules_lock );
195- #endif
196- synclist_destroy (& glb -> registered_processes );
197- synclist_destroy (& glb -> processes_table );
198- // Destroy every remaining refc binaries.
199191 struct ListHead * item ;
200192 struct ListHead * tmp ;
201- struct ListHead * refc_binaries = synclist_nolock (& glb -> refc_binaries );
202- MUTABLE_LIST_FOR_EACH (item , tmp , refc_binaries ) {
203- struct RefcBinary * refc = GET_LIST_ENTRY (item , struct RefcBinary , head );
204- refc_binary_destroy (refc , glb );
205- }
206- synclist_destroy (& glb -> refc_binaries );
207193
208194 struct ListHead * open_avm_packs = synclist_nolock (& glb -> avmpack_data );
209195 MUTABLE_LIST_FOR_EACH (item , tmp , open_avm_packs ) {
@@ -218,6 +204,22 @@ COLD_FUNC void globalcontext_destroy(GlobalContext *glb)
218204 }
219205 synclist_destroy (& glb -> listeners );
220206
207+ // Destroy select events before resources
208+ struct ListHead * select_events = synclist_nolock (& glb -> select_events );
209+ MUTABLE_LIST_FOR_EACH (item , tmp , select_events ) {
210+ struct SelectEvent * select_event = GET_LIST_ENTRY (item , struct SelectEvent , head );
211+ free ((void * ) select_event );
212+ }
213+ synclist_destroy (& glb -> select_events );
214+
215+ // Destroy refc binaries including resources
216+ struct ListHead * refc_binaries = synclist_nolock (& glb -> refc_binaries );
217+ MUTABLE_LIST_FOR_EACH (item , tmp , refc_binaries ) {
218+ struct RefcBinary * refc = GET_LIST_ENTRY (item , struct RefcBinary , head );
219+ refc_binary_destroy (refc , glb );
220+ }
221+ synclist_destroy (& glb -> refc_binaries );
222+
221223 // Destroy resource types
222224 struct ListHead * resource_types = synclist_nolock (& glb -> resource_types );
223225 MUTABLE_LIST_FOR_EACH (item , tmp , resource_types ) {
@@ -226,12 +228,13 @@ COLD_FUNC void globalcontext_destroy(GlobalContext *glb)
226228 }
227229 synclist_destroy (& glb -> resource_types );
228230
229- struct ListHead * select_events = synclist_nolock (& glb -> select_events );
230- MUTABLE_LIST_FOR_EACH (item , tmp , select_events ) {
231- struct SelectEvent * select_event = GET_LIST_ENTRY (item , struct SelectEvent , head );
232- free ((void * ) select_event );
233- }
234- synclist_destroy (& glb -> select_events );
231+ #ifndef AVM_NO_SMP
232+ smp_condvar_destroy (glb -> schedulers_cv );
233+ smp_mutex_destroy (glb -> schedulers_mutex );
234+ smp_rwlock_destroy (glb -> modules_lock );
235+ #endif
236+ synclist_destroy (& glb -> registered_processes );
237+ synclist_destroy (& glb -> processes_table );
235238
236239 free (glb );
237240}
0 commit comments