From b1d40ddfe23fd9551b89cdcfa52d1c23fc667f8a Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Wed, 21 Aug 2019 09:58:10 +0200 Subject: Modify ossl_method_store_add() to handle reference counting Because this function affects the reference count on failure (the call to impl_free() does this), it may as well handle incrementing it as well to indicate the extra reference in the method store. Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/9650) --- crypto/property/property.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'crypto/property') diff --git a/crypto/property/property.c b/crypto/property/property.c index c3fa8df9c6..6576ba0fd2 100644 --- a/crypto/property/property.c +++ b/crypto/property/property.c @@ -174,8 +174,9 @@ static int ossl_method_store_insert(OSSL_METHOD_STORE *store, ALGORITHM *alg) } int ossl_method_store_add(OSSL_METHOD_STORE *store, - int nid, const char *properties, - void *method, void (*method_destruct)(void *)) + int nid, const char *properties, void *method, + int (*method_up_ref)(void *), + void (*method_destruct)(void *)) { ALGORITHM *alg = NULL; IMPLEMENTATION *impl; @@ -190,6 +191,8 @@ int ossl_method_store_add(OSSL_METHOD_STORE *store, impl = OPENSSL_malloc(sizeof(*impl)); if (impl == NULL) return 0; + if (method_up_ref != NULL && !method_up_ref(method)) + return 0; impl->method = method; impl->method_destruct = method_destruct; -- cgit v1.2.3