Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/libAtomVM/globalcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ GlobalContext *globalcontext_new(void)
#ifndef AVM_NO_SMP
glb->modules_lock = smp_rwlock_create();
if (IS_NULL_PTR(glb->modules_lock)) {
free(glb->modules_table);
valueshashtable_destroy(glb->modules_table);
atom_table_destroy(glb->atom_table);
free(glb);
return NULL;
Expand Down Expand Up @@ -140,7 +140,7 @@ GlobalContext *globalcontext_new(void)
#ifndef AVM_NO_SMP
smp_rwlock_destroy(glb->modules_lock);
#endif
free(glb->modules_table);
valueshashtable_destroy(glb->modules_table);
atom_table_destroy(glb->atom_table);
free(glb);
return NULL;
Expand All @@ -155,7 +155,7 @@ GlobalContext *globalcontext_new(void)
#ifndef AVM_NO_SMP
smp_rwlock_destroy(glb->modules_lock);
#endif
free(glb->modules_table);
valueshashtable_destroy(glb->modules_table);
atom_table_destroy(glb->atom_table);
free(glb);
return NULL;
Expand All @@ -171,7 +171,7 @@ GlobalContext *globalcontext_new(void)
#ifndef AVM_NO_SMP
smp_rwlock_destroy(glb->modules_lock);
#endif
free(glb->modules_table);
valueshashtable_destroy(glb->modules_table);
atom_table_destroy(glb->atom_table);
free(glb);
return NULL;
Expand All @@ -185,7 +185,7 @@ GlobalContext *globalcontext_new(void)
#ifndef AVM_NO_SMP
smp_rwlock_destroy(glb->modules_lock);
#endif
free(glb->modules_table);
valueshashtable_destroy(glb->modules_table);
atom_table_destroy(glb->atom_table);
free(glb);
return NULL;
Expand All @@ -199,7 +199,7 @@ GlobalContext *globalcontext_new(void)
#ifndef AVM_NO_SMP
smp_rwlock_destroy(glb->modules_lock);
#endif
free(glb->modules_table);
valueshashtable_destroy(glb->modules_table);
atom_table_destroy(glb->atom_table);
free(glb);
return NULL;
Expand All @@ -215,7 +215,7 @@ GlobalContext *globalcontext_new(void)
resource_type_destroy(glb->posix_fd_resource_type);
#endif
smp_rwlock_destroy(glb->modules_lock);
free(glb->modules_table);
valueshashtable_destroy(glb->modules_table);
atom_table_destroy(glb->atom_table);
free(glb);
return NULL;
Expand All @@ -227,7 +227,7 @@ GlobalContext *globalcontext_new(void)
resource_type_destroy(glb->posix_fd_resource_type);
#endif
smp_rwlock_destroy(glb->modules_lock);
free(glb->modules_table);
valueshashtable_destroy(glb->modules_table);
atom_table_destroy(glb->atom_table);
free(glb);
return NULL;
Expand Down Expand Up @@ -311,6 +311,10 @@ COLD_FUNC void globalcontext_destroy(GlobalContext *glb)
synclist_destroy(&glb->registered_processes);
synclist_destroy(&glb->processes_table);

valueshashtable_destroy(glb->modules_table);
free(glb->modules_by_index);
atom_table_destroy(glb->atom_table);

free(glb);
}

Expand Down
23 changes: 23 additions & 0 deletions src/libAtomVM/valueshashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,26 @@ int valueshashtable_has_key(const struct ValuesHashTable *hash_table, uintptr_t
SMP_UNLOCK(hash_table);
return 0;
}

void valueshashtable_destroy(struct ValuesHashTable *hash_table)
{
if (IS_NULL_PTR(hash_table)) {
return;
}

for (size_t i = 0; i < hash_table->capacity; i++) {
struct HNode *node = hash_table->buckets[i];
while (node) {
struct HNode *tmp = node->next;
free(node);
node = tmp;
}
}
free(hash_table->buckets);

#ifndef AVM_NO_SMP
smp_rwlock_destroy(hash_table->lock);
#endif

free(hash_table);
}
1 change: 1 addition & 0 deletions src/libAtomVM/valueshashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct ValuesHashTable
};

struct ValuesHashTable *valueshashtable_new(void);
void valueshashtable_destroy(struct ValuesHashTable *hash_table);
int valueshashtable_insert(struct ValuesHashTable *hash_table, uintptr_t key, uintptr_t value);
uintptr_t valueshashtable_get_value(const struct ValuesHashTable *hash_table, uintptr_t key, uintptr_t default_value);
int valueshashtable_has_key(const struct ValuesHashTable *hash_table, uintptr_t key);
Expand Down
Loading