@@ -92,15 +92,15 @@ static enum ModuleLoadResult module_populate_atoms_table(Module *this_module, ui
92
92
93
93
static enum ModuleLoadResult module_build_imported_functions_table (Module * this_module , uint8_t * table_data , GlobalContext * glb )
94
94
{
95
- int functions_count = READ_32_ALIGNED (table_data + 8 );
95
+ this_module -> functions_count = READ_32_ALIGNED (table_data + 8 );
96
96
97
- this_module -> imported_funcs = calloc (functions_count , sizeof (struct ExportedFunction * ));
97
+ this_module -> imported_funcs = calloc (this_module -> functions_count , sizeof (struct ExportedFunction * ));
98
98
if (IS_NULL_PTR (this_module -> imported_funcs )) {
99
99
fprintf (stderr , "Cannot allocate memory while loading module (line: %i).\n" , __LINE__ );
100
100
return MODULE_ERROR_FAILED_ALLOCATION ;
101
101
}
102
102
103
- for (int i = 0 ; i < functions_count ; i ++ ) {
103
+ for (int i = 0 ; i < this_module -> functions_count ; ++ i ) {
104
104
int local_module_atom_index = READ_32_ALIGNED (table_data + i * 12 + 12 );
105
105
int local_function_atom_index = READ_32_ALIGNED (table_data + i * 12 + 4 + 12 );
106
106
AtomString module_atom = module_get_atom_string_by_id (this_module , local_module_atom_index , glb );
@@ -319,12 +319,30 @@ Module *module_new_from_iff_binary(GlobalContext *global, const void *iff_binary
319
319
COLD_FUNC void module_destroy (Module * module )
320
320
{
321
321
free (module -> labels );
322
+ for (int i = 0 ; i < module -> functions_count ; ++ i ) {
323
+ const struct ExportedFunction * fun = module -> imported_funcs [i ];
324
+ switch (fun -> type ) {
325
+ // Preallocated function types
326
+ case NIFFunctionType :
327
+ case BIFFunctionType :
328
+ case GCBIFFunctionType :
329
+ break ;
330
+ default :
331
+ free ((void * ) fun );
332
+ }
333
+ }
322
334
free (module -> imported_funcs );
323
335
free (module -> literals_table );
324
336
free (module -> local_atoms_to_global_table );
325
337
if (module -> free_literals_data ) {
326
338
free (module -> literals_data );
327
339
}
340
+ free (module -> line_refs );
341
+ free (module -> filenames );
342
+ struct ListHead * item , * tmp ;
343
+ MUTABLE_LIST_FOR_EACH (item , tmp , & module -> line_ref_offsets ) {
344
+ free (GET_LIST_ENTRY (item , struct LineRefOffset , head ));
345
+ }
328
346
#ifndef AVM_NO_SMP
329
347
smp_mutex_destroy (module -> mutex );
330
348
#endif
0 commit comments