Skip to content

Commit

Permalink
CID 465959: Resource leaks
Browse files Browse the repository at this point in the history
Fix resource leak, also covers CID 465960

Signed-off-by: Simo Sorce <[email protected]>
  • Loading branch information
simo5 committed Oct 2, 2023
1 parent f9b04f9 commit 2e8c26b
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/keymgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,7 @@ static void *p11prov_common_gen(struct key_generator *ctx,
/* generate unique id for the key */
ret = p11prov_GenerateRandom(ctx->provctx, sh, id, sizeof(id));
if (ret != CKR_OK) {
p11prov_return_session(session);
return NULL;
goto done;
}
cka_id.type = CKA_ID;
cka_id.pValue = id;
Expand All @@ -523,28 +522,26 @@ static void *p11prov_common_gen(struct key_generator *ctx,
pubkey_template, pubtsize, privkey_template,
privtsize, &pubkey, &privkey);
if (ret != CKR_OK) {
p11prov_return_session(session);
return NULL;
goto done;
}

ret = p11prov_obj_from_handle(ctx->provctx, session, pubkey, &pub_key);
if (ret != CKR_OK) {
p11prov_return_session(session);
return NULL;
goto done;
}

ret = p11prov_obj_from_handle(ctx->provctx, session, privkey, &priv_key);
if (ret != CKR_OK) {
p11prov_return_session(session);
return NULL;
goto done;
}

ret = p11prov_merge_pub_attrs_into_priv(pub_key, priv_key);

done:
if (ret != CKR_OK) {
p11prov_return_session(session);
return NULL;
p11prov_obj_free(priv_key);
priv_key = NULL;
}

p11prov_return_session(session);
p11prov_obj_free(pub_key);
return priv_key;
Expand Down

0 comments on commit 2e8c26b

Please sign in to comment.