Skip to content

Commit 0edecfd

Browse files
committed
Split secp256k1_ecmult_gen_context_teardown() out of secp256k1_ecmult_gen_context_clear
The 'teardown' naming is to complement the 'build' function name. To 'build' allocates and sets up the memory for ctx->prec. To 'teardown' frees the memory.
1 parent 2f05e69 commit 0edecfd

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

src/ecmult_gen.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context* ctx)
3232
static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context* ctx, const secp256k1_callback* cb);
3333
static void secp256k1_ecmult_gen_context_clone(secp256k1_ecmult_gen_context *dst,
3434
const secp256k1_ecmult_gen_context* src, const secp256k1_callback* cb);
35+
#ifndef USE_ECMULT_STATIC_PRECOMPUTATION
36+
static void secp256k1_ecmult_gen_context_teardown(secp256k1_ecmult_gen_context* ctx);
37+
#endif
3538
static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context* ctx);
3639
static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context* ctx);
3740

src/ecmult_gen_impl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,13 @@ static void secp256k1_ecmult_gen_context_clone(secp256k1_ecmult_gen_context *dst
112112
}
113113
}
114114

115-
static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context *ctx) {
116115
#ifndef USE_ECMULT_STATIC_PRECOMPUTATION
116+
static void secp256k1_ecmult_gen_context_teardown(secp256k1_ecmult_gen_context *ctx) {
117117
free(ctx->prec);
118+
}
118119
#endif
120+
121+
static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context *ctx) {
119122
SECP256K1_CLEANSE(ctx->blind);
120123
SECP256K1_CLEANSE(ctx->initial);
121124
ctx->prec = NULL;

src/gen_context.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ int main(int argc, char **argv) {
6464
}
6565
}
6666
fprintf(fp,"};\n");
67+
#ifndef USE_ECMULT_STATIC_PRECOMPUTATION
68+
secp256k1_ecmult_gen_context_teardown(&ctx);
69+
#endif
6770
secp256k1_ecmult_gen_context_clear(&ctx);
6871

6972
fprintf(fp, "#undef SC\n");

src/secp256k1.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ void secp256k1_context_destroy(secp256k1_context* ctx) {
9393
if (ctx != NULL) {
9494
secp256k1_ecmult_context_teardown(&ctx->ecmult_ctx);
9595
SECP256K1_CLEANSE(ctx->ecmult_ctx);
96+
#ifndef USE_ECMULT_STATIC_PRECOMPUTATION
97+
secp256k1_ecmult_gen_context_teardown(&ctx->ecmult_gen_ctx);
98+
#endif
9699
secp256k1_ecmult_gen_context_clear(&ctx->ecmult_gen_ctx);
97100

98101
free(ctx);

0 commit comments

Comments
 (0)