Skip to content

Commit 4b3dfc5

Browse files
committed
Add missing PKCS11_OBJECT reference
1 parent 9741a47 commit 4b3dfc5

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/p11_key.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* libp11, a simple layer on to of PKCS#11 API
22
* Copyright (C) 2005 Olaf Kirch <[email protected]>
3-
* Copyright (C) 2016-2018 Michał Trojnara <[email protected]>
3+
* Copyright (C) 2016-2024 Michał Trojnara <[email protected]>
44
*
55
* This library is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU Lesser General Public
@@ -507,11 +507,10 @@ EVP_PKEY *pkcs11_get_key(PKCS11_OBJECT_private *key0, CK_OBJECT_CLASS object_cla
507507
pkcs11_set_ex_data_ec(ec_key, NULL);
508508
#else
509509
ret = EVP_PKEY_dup(key->evp_key);
510-
if (key->object_class != CKO_PRIVATE_KEY) {
511-
/* Public key -> detach and free PKCS11_OBJECT */
510+
if (key->object_class == CKO_PRIVATE_KEY)
511+
pkcs11_object_ref(key);
512+
else /* Public key -> detach PKCS11_OBJECT */
512513
pkcs11_set_ex_data_ec((EC_KEY *)EVP_PKEY_get0_EC_KEY(ret), NULL);
513-
pkcs11_object_free(key);
514-
}
515514
#endif
516515
break;
517516
default:

0 commit comments

Comments
 (0)