Skip to content

Commit

Permalink
Merge pull request #29 from codefruit/fix-bcal-cmac-free-memleak
Browse files Browse the repository at this point in the history
Fix bcal cmac free memleak
DavyLandman authored Mar 11, 2022
2 parents f50f4d9 + 58abee7 commit d78588a
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions AESLib.c
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ void aes128_cbc_enc(const uint8_t* key, const uint8_t* iv, void* data, const uin
uint8_t r;
r = bcal_cbc_init(&aes128_desc, key, 128, &ctx);
if (r) {
bcal_cbc_free(&ctx);
return;
}
bcal_cbc_encMsg(iv, data, data_len / 16, &ctx);
@@ -50,6 +51,7 @@ void aes192_cbc_enc(const uint8_t* key, const uint8_t* iv, void* data, const uin
uint8_t r;
r = bcal_cbc_init(&aes192_desc, key, 192, &ctx);
if (r) {
bcal_cbc_free(&ctx);
return;
}
bcal_cbc_encMsg(iv, data, data_len / 16, &ctx);
6 changes: 4 additions & 2 deletions bcal-basic.c
Original file line number Diff line number Diff line change
@@ -57,9 +57,11 @@ void bcal_cipher_free(bcgen_ctx_t* ctx){
return;
bc_free_fpt free_fpt;
free_fpt = (bc_free_fpt)(pgm_read_word(&(ctx->desc_ptr->free)));
if(free_fpt)
if(free_fpt) {
free_fpt((ctx->ctx));
free(ctx->ctx);
} else {
free(ctx->ctx);
}
}

void bcal_cipher_enc(void* block, const bcgen_ctx_t* ctx){
1 change: 1 addition & 0 deletions bcal-cmac.c
Original file line number Diff line number Diff line change
@@ -91,6 +91,7 @@ void bcal_cmac_free(bcal_cmac_ctx_t* ctx){
free(ctx->accu);
free(ctx->k1);
free(ctx->k2);
free(ctx->lastblock);
bcal_cipher_free(&(ctx->cctx));
}

0 comments on commit d78588a

Please sign in to comment.