Skip to content

Commit

Permalink
scratch: unify allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
apoelstra committed May 25, 2019
1 parent c2b028a commit 5a4bc0b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/scratch_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#include "scratch.h"

static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t max_size) {
secp256k1_scratch* ret = (secp256k1_scratch*)checked_malloc(error_callback, sizeof(*ret));
const size_t base_alloc = ((sizeof(secp256k1_scratch) + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT;
void *alloc = checked_malloc(error_callback, base_alloc + max_size);
secp256k1_scratch* ret = (secp256k1_scratch *)alloc;
if (ret != NULL) {
memset(ret, 0, sizeof(*ret));
memcpy(ret->magic, "scratch", 8);
ret->data = (secp256k1_scratch*)checked_malloc(error_callback, max_size);
ret->data = (void *) ((char *) alloc + base_alloc);
ret->max_size = max_size;
}
return ret;
Expand All @@ -29,7 +31,6 @@ static void secp256k1_scratch_destroy(const secp256k1_callback* error_callback,
return;
}
memset(scratch->magic, 0, sizeof(scratch->magic));
free(scratch->data);
free(scratch);
}
}
Expand Down

0 comments on commit 5a4bc0b

Please sign in to comment.