[PATCH 2/5] crypt32: Free the existing certificate in add_cert_to_store() when necessary (Valgrind).
Sven Baars
sbaars at codeweavers.com
Fri Feb 18 14:56:13 CST 2022
Signed-off-by: Sven Baars <sbaars at codeweavers.com>
---
dlls/crypt32/cert.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/dlls/crypt32/cert.c b/dlls/crypt32/cert.c
index 33811dfadc1..5fc76c9556f 100644
--- a/dlls/crypt32/cert.c
+++ b/dlls/crypt32/cert.c
@@ -214,7 +214,8 @@ static BOOL add_cert_to_store(WINECRYPT_CERTSTORE *store, const CERT_CONTEXT *ce
{
TRACE("found matching certificate, not adding\n");
SetLastError(CRYPT_E_EXISTS);
- return FALSE;
+ ret = FALSE;
+ goto done;
}
break;
case CERT_STORE_ADD_REPLACE_EXISTING:
@@ -231,8 +232,7 @@ static BOOL add_cert_to_store(WINECRYPT_CERTSTORE *store, const CERT_CONTEXT *ce
if (existing)
{
Context_CopyProperties(existing, cert);
- if (ret_context)
- *ret_context = CertDuplicateCertificateContext(existing);
+ *ret_context = existing;
return TRUE;
}
break;
@@ -241,7 +241,8 @@ static BOOL add_cert_to_store(WINECRYPT_CERTSTORE *store, const CERT_CONTEXT *ce
{
TRACE("existing certificate is newer, not adding\n");
SetLastError(CRYPT_E_EXISTS);
- return FALSE;
+ ret = FALSE;
+ goto done;
}
break;
case CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES:
@@ -251,7 +252,8 @@ static BOOL add_cert_to_store(WINECRYPT_CERTSTORE *store, const CERT_CONTEXT *ce
{
TRACE("existing certificate is newer, not adding\n");
SetLastError(CRYPT_E_EXISTS);
- return FALSE;
+ ret = FALSE;
+ goto done;
}
inherit_props = TRUE;
}
@@ -262,13 +264,14 @@ static BOOL add_cert_to_store(WINECRYPT_CERTSTORE *store, const CERT_CONTEXT *ce
if(!store) {
if(ret_context)
*ret_context = CertDuplicateCertificateContext(cert);
- return TRUE;
+ ret = TRUE;
+ goto done;
}
ret = store->vtbl->certs.addContext(store, context_from_ptr(cert), existing ? context_from_ptr(existing) : NULL,
(ret_context || inherit_props) ? &new_context : NULL, use_link);
if(!ret)
- return FALSE;
+ goto done;
if(inherit_props)
Context_CopyProperties(context_ptr(new_context), existing);
@@ -278,7 +281,12 @@ static BOOL add_cert_to_store(WINECRYPT_CERTSTORE *store, const CERT_CONTEXT *ce
else if(new_context)
Context_Release(new_context);
+done:
TRACE("returning %d\n", ret);
+
+ if (existing)
+ CertFreeCertificateContext(existing);
+
return ret;
}
--
2.30.0.335.ge6362826a0
More information about the wine-devel
mailing list