From 37315f877ef27d0f8585389f0c83cd00a31577c1 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Mon, 21 Nov 2016 15:22:48 +0100 Subject: Reworked server and client to do one mix and shutdown. This is done as cleanly as possible to track down any memory leaks. unfortunately there is still one async operation running on the nodes. when there should be none. So the nodes are still forced to stop with a. io_service.stop(). --- libcmix/cmix.c | 36 ++++++++++++++++++++++++------------ libcmix/cmix.h | 2 ++ 2 files changed, 26 insertions(+), 12 deletions(-) (limited to 'libcmix') diff --git a/libcmix/cmix.c b/libcmix/cmix.c index d21dab5..c60f441 100644 --- a/libcmix/cmix.c +++ b/libcmix/cmix.c @@ -24,6 +24,17 @@ struct CMixContext initialize_cmix_context(struct Api api) { }; } +enum cmix_error alloc_mix(struct CMixContext* ctx) { + ctx->r = (GroupElement*) calloc(ctx->nr_participants, sizeof(GroupElement)); + ctx->s = (GroupElement*) calloc(ctx->nr_participants, sizeof(GroupElement)); + ctx->permutation = (unsigned int*) calloc(ctx->nr_participants, sizeof(unsigned int)); + ctx->pirs = (GroupElement*) calloc(ctx->nr_participants, sizeof(GroupElement)); + if(!ctx->r || !ctx->s || !ctx->permutation || !ctx->pirs) { + return out_of_memory; + } + return no_error; +} + void release_mix(struct CMixContext* ctx) { for(size_t i = 0; i < ctx->nr_participants; ++i) { ctx->api.free_group_element(ctx->r[i]); @@ -31,9 +42,18 @@ void release_mix(struct CMixContext* ctx) { ctx->api.free_group_element(ctx->pirs[i]); } free(ctx->r); + ctx->r = NULL; + free(ctx->s); + ctx->s = NULL; + free(ctx->permutation); + ctx->permutation = NULL; + free(ctx->pirs); + ctx->pirs = NULL; + + ctx->nr_participants = 0; } void deinitialize(struct CMixContext* ctx) @@ -77,17 +97,6 @@ enum cmix_error add_public_share(struct CMixContext const* ctx, char* buffer, ch ctx->api.free_group_element(el); } -enum cmix_error alloc_mix(struct CMixContext* ctx) { - ctx->r = (GroupElement*) calloc(ctx->nr_participants, sizeof(GroupElement)); - ctx->s = (GroupElement*) calloc(ctx->nr_participants, sizeof(GroupElement)); - ctx->permutation = (unsigned int*) calloc(ctx->nr_participants, sizeof(unsigned int)); - ctx->pirs = (GroupElement*) calloc(ctx->nr_participants, sizeof(GroupElement)); - if(!ctx->r || !ctx->s || !ctx->permutation || !ctx->pirs) { - return out_of_memory; - } - return no_error; -} - enum cmix_error start_mix(struct CMixContext* ctx, size_t nr_participants) { release_mix(ctx); ctx->nr_participants = nr_participants; @@ -95,7 +104,10 @@ enum cmix_error start_mix(struct CMixContext* ctx, size_t nr_participants) { } enum cmix_error generate_permutation(struct CMixContext* ctx) { - ctx->permutation = (unsigned int*) calloc(ctx->nr_participants, sizeof(unsigned int)); + if (ctx->nr_participants == 0) { + return no_error; + } + for(unsigned int i = 0; i < ctx->nr_participants; ++i) { ctx->permutation[i] = i; } diff --git a/libcmix/cmix.h b/libcmix/cmix.h index 057fd60..8e6f598 100644 --- a/libcmix/cmix.h +++ b/libcmix/cmix.h @@ -73,6 +73,8 @@ enum cmix_error get_pub_key_hash(struct CMixContext const* ctx, char** buffer); enum cmix_error start_mix(struct CMixContext* ctx, size_t nr_participants); +void release_mix(struct CMixContext* ctx); + enum cmix_error initialize_mix_randomness(struct CMixContext* ctx); enum cmix_error generate_random_message(struct CMixContext* ctx, char* buffer); -- cgit v1.2.3-70-g09d2