diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-11-21 15:22:48 +0100 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-11-21 15:22:48 +0100 |
| commit | 37315f877ef27d0f8585389f0c83cd00a31577c1 (patch) | |
| tree | caead8a996811c154859d97ae3c5c946ae8da4b6 /libcmix/cmix.c | |
| parent | e4cf0d04c4afff98603df440d12a4a19b3717a34 (diff) | |
| download | cmix-37315f877ef27d0f8585389f0c83cd00a31577c1.tar.gz cmix-37315f877ef27d0f8585389f0c83cd00a31577c1.tar.bz2 cmix-37315f877ef27d0f8585389f0c83cd00a31577c1.zip | |
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().
Diffstat (limited to 'libcmix/cmix.c')
| -rw-r--r-- | libcmix/cmix.c | 36 |
1 files changed, 24 insertions, 12 deletions
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; } |
