Skip to content

Commit

Permalink
Decrement ref counter only once on key object free
Browse files Browse the repository at this point in the history
  • Loading branch information
pugo committed Mar 12, 2024
1 parent 697ac03 commit 9882fcf
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/p11_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ void pkcs11_object_free(PKCS11_OBJECT_private *obj)
if(!obj)
return;

if (pkcs11_atomic_add(&obj->refcnt, -1, &obj->lock) != 0)
return;
if (obj->evp_key) {
/* When the EVP object is reference count goes to zero,
* it will call this function again. */
Expand All @@ -195,6 +193,10 @@ void pkcs11_object_free(PKCS11_OBJECT_private *obj)
EVP_PKEY_free(pkey);
return;
}

if (pkcs11_atomic_add(&obj->refcnt, -1, &obj->lock) != 0)
return;

pkcs11_slot_unref(obj->slot);
X509_free(obj->x509);
OPENSSL_free(obj->label);
Expand Down

0 comments on commit 9882fcf

Please sign in to comment.