summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2019-08-21 09:58:10 +0200
committerRichard Levitte <levitte@openssl.org>2019-08-22 01:50:30 +0200
commitb1d40ddfe23fd9551b89cdcfa52d1c23fc667f8a (patch)
tree1eb6cc4b725753f4f20a5e2ded72fcd1a919a114 /crypto
parentd32d304836caaca475c21a82b94e494898cb60c5 (diff)
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 <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/9650)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/evp/evp_fetch.c8
-rw-r--r--crypto/property/property.c7
2 files changed, 8 insertions, 7 deletions
diff --git a/crypto/evp/evp_fetch.c b/crypto/evp/evp_fetch.c
index 5c100dd1eb..41dee721a4 100644
--- a/crypto/evp/evp_fetch.c
+++ b/crypto/evp/evp_fetch.c
@@ -132,11 +132,9 @@ static int put_method_in_store(OPENSSL_CTX *libctx, void *store,
&& (store = get_default_method_store(libctx)) == NULL)
return 0;
- if (methdata->refcnt_up_method(method)
- && ossl_method_store_add(store, methid, propdef, method,
- methdata->destruct_method))
- return 1;
- return 0;
+ return ossl_method_store_add(store, methid, propdef, method,
+ methdata->refcnt_up_method,
+ methdata->destruct_method);
}
static void *construct_method(const char *name, const OSSL_DISPATCH *fns,
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;