Skip to content

Commit

Permalink
Address more memory leak and speck deinit issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishcoleman committed May 15, 2024
1 parent 51eb3d7 commit 5f1b33c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/sn_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ void calculate_shared_secrets (struct n3n_runtime_data *sss) {
// calculate common shared secret (ECDH)
generate_shared_secret(user->shared_secret, sss->private_key, user->public_key);
// prepare for use as key
user->shared_secret_ctx = (he_context_t*)calloc(1, sizeof(speck_context_t));
speck_init((speck_context_t**)&user->shared_secret_ctx, user->shared_secret, 128);
}
}
Expand Down Expand Up @@ -304,7 +303,7 @@ int load_allowed_sn_community (struct n3n_runtime_data *sss) {
HASH_ITER(hh, comm->allowed_users, user, tmp_user) {
free(user->shared_secret_ctx);
HASH_DEL(comm->allowed_users, user);
free(user);
speck_deinit(user);
}

// remove community
Expand Down Expand Up @@ -950,6 +949,15 @@ void sn_term (struct n3n_runtime_data *sss) {
HASH_DEL(community->assoc, assoc);
free(assoc);
}

// remove allowed users from community
sn_user_t *user, *tmp_user;
HASH_ITER(hh, community->allowed_users, user, tmp_user) {
speck_deinit(user->shared_secret_ctx);
HASH_DEL(community->allowed_users, user);
free(user);
}

HASH_DEL(sss->communities, community);
free(community);
}
Expand Down

0 comments on commit 5f1b33c

Please sign in to comment.