Be more careful with TRY: avoid when free needed

This commit is contained in:
Ramana Kumar 2022-10-20 08:33:47 +01:00
parent e810aebc28
commit e023376c8e
No known key found for this signature in database
GPG Key ID: ED471C788B900433

View File

@ -805,14 +805,16 @@ C_KZG_RET load_trusted_setup(KZGSettings *out, FILE *in) {
out->fs = (FFTSettings*)malloc(sizeof(FFTSettings)); out->fs = (FFTSettings*)malloc(sizeof(FFTSettings));
TRY(new_fft_settings((FFTSettings*)out->fs, max_scale)); C_KZG_RET ret;
ret = new_fft_settings((FFTSettings*)out->fs, max_scale);
if (ret != C_KZG_OK) { free(g1_projective); return ret; }
TRY(fft_g1(out->g1_values, g1_projective, true, FIELD_ELEMENTS_PER_BLOB, out->fs)); ret = fft_g1(out->g1_values, g1_projective, true, FIELD_ELEMENTS_PER_BLOB, out->fs);
free(g1_projective);
if (ret != C_KZG_OK) return ret;
TRY(reverse_bit_order(out->g1_values, sizeof(g1_t), FIELD_ELEMENTS_PER_BLOB)); TRY(reverse_bit_order(out->g1_values, sizeof(g1_t), FIELD_ELEMENTS_PER_BLOB));
free(g1_projective);
return C_KZG_OK; return C_KZG_OK;
} }
@ -992,7 +994,9 @@ static C_KZG_RET compute_kzg_proof(KZGProof *out, const Polynomial p, const BLSF
fr_t *inverses_in, *inverses; fr_t *inverses_in, *inverses;
TRY(new_fr_array(&inverses_in, FIELD_ELEMENTS_PER_BLOB)); TRY(new_fr_array(&inverses_in, FIELD_ELEMENTS_PER_BLOB));
TRY(new_fr_array(&inverses, FIELD_ELEMENTS_PER_BLOB)); C_KZG_RET ret;
ret = new_fr_array(&inverses, FIELD_ELEMENTS_PER_BLOB);
if (ret != C_KZG_OK) { free(inverses_in); return ret; }
for (i = 0; i < FIELD_ELEMENTS_PER_BLOB; i++) { for (i = 0; i < FIELD_ELEMENTS_PER_BLOB; i++) {
if (fr_equal(x, &roots_of_unity[i])) { if (fr_equal(x, &roots_of_unity[i])) {
@ -1004,7 +1008,8 @@ static C_KZG_RET compute_kzg_proof(KZGProof *out, const Polynomial p, const BLSF
fr_sub(&inverses_in[i], &roots_of_unity[i], x); fr_sub(&inverses_in[i], &roots_of_unity[i], x);
} }
TRY(fr_batch_inv(inverses, inverses_in, FIELD_ELEMENTS_PER_BLOB)); ret = fr_batch_inv(inverses, inverses_in, FIELD_ELEMENTS_PER_BLOB);
if (ret != C_KZG_OK) { free(inverses_in); free(inverses); return ret; }
for (i = 0; i < FIELD_ELEMENTS_PER_BLOB; i++) { for (i = 0; i < FIELD_ELEMENTS_PER_BLOB; i++) {
fr_mul(&q[i], &q[i], &inverses[i]); fr_mul(&q[i], &q[i], &inverses[i]);
@ -1018,7 +1023,8 @@ static C_KZG_RET compute_kzg_proof(KZGProof *out, const Polynomial p, const BLSF
fr_sub(&tmp, x, &roots_of_unity[i]); fr_sub(&tmp, x, &roots_of_unity[i]);
fr_mul(&inverses_in[i], &tmp, x); fr_mul(&inverses_in[i], &tmp, x);
} }
TRY(fr_batch_inv(inverses, inverses_in, FIELD_ELEMENTS_PER_BLOB)); ret = fr_batch_inv(inverses, inverses_in, FIELD_ELEMENTS_PER_BLOB);
if (ret != C_KZG_OK) { free(inverses_in); free(inverses); return ret; }
for (i = 0; i < FIELD_ELEMENTS_PER_BLOB; i++) { for (i = 0; i < FIELD_ELEMENTS_PER_BLOB; i++) {
fr_sub(&tmp, &p[i], &y); fr_sub(&tmp, &p[i], &y);
fr_mul(&tmp, &tmp, &roots_of_unity[i]); fr_mul(&tmp, &tmp, &roots_of_unity[i]);