From 7324db2b75abbf32cc47bb3497c6c8cc32af41f0 Mon Sep 17 00:00:00 2001 From: Rushil Mehra Date: Tue, 3 Sep 2024 08:04:30 -0700 Subject: [PATCH] Use ForeignType::into_ptr wherever applicable --- boring/src/dsa.rs | 3 +-- boring/src/ssl/mod.rs | 15 ++++++--------- boring/src/x509/mod.rs | 4 +--- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/boring/src/dsa.rs b/boring/src/dsa.rs index 60c0c197..d9c35505 100644 --- a/boring/src/dsa.rs +++ b/boring/src/dsa.rs @@ -280,8 +280,7 @@ impl Dsa { let dsa = Dsa::from_ptr(cvt_p(ffi::DSA_new())?); cvt(DSA_set0_pqg(dsa.0, p.as_ptr(), q.as_ptr(), g.as_ptr()))?; mem::forget((p, q, g)); - cvt(DSA_set0_key(dsa.0, pub_key.as_ptr(), ptr::null_mut()))?; - mem::forget(pub_key); + cvt(DSA_set0_key(dsa.0, pub_key.into_ptr(), ptr::null_mut()))?; Ok(dsa) } } diff --git a/boring/src/ssl/mod.rs b/boring/src/ssl/mod.rs index 12ffedf5..04e0ee43 100644 --- a/boring/src/ssl/mod.rs +++ b/boring/src/ssl/mod.rs @@ -1068,9 +1068,9 @@ impl SslContextBuilder { assert!(!self.is_rpk, "This API is not supported for RPK"); unsafe { - let ptr = cert_store.as_ptr(); - cvt(ffi::SSL_CTX_set0_verify_cert_store(self.as_ptr(), ptr) as c_int)?; - mem::forget(cert_store); + cvt( + ffi::SSL_CTX_set0_verify_cert_store(self.as_ptr(), cert_store.into_ptr()) as c_int, + )?; Ok(()) } @@ -1083,8 +1083,7 @@ impl SslContextBuilder { assert!(!self.is_rpk, "This API is not supported for RPK"); unsafe { - ffi::SSL_CTX_set_cert_store(self.as_ptr(), cert_store.as_ptr()); - mem::forget(cert_store); + ffi::SSL_CTX_set_cert_store(self.as_ptr(), cert_store.into_ptr()); } } @@ -1260,8 +1259,7 @@ impl SslContextBuilder { assert!(!self.is_rpk, "This API is not supported for RPK"); unsafe { - cvt(ffi::SSL_CTX_add_extra_chain_cert(self.as_ptr(), cert.as_ptr()) as c_int)?; - mem::forget(cert); + cvt(ffi::SSL_CTX_add_extra_chain_cert(self.as_ptr(), cert.into_ptr()) as c_int)?; Ok(()) } } @@ -2742,8 +2740,7 @@ impl SslRef { ); unsafe { - cvt(ffi::SSL_set0_verify_cert_store(self.as_ptr(), cert_store.as_ptr()) as c_int)?; - mem::forget(cert_store); + cvt(ffi::SSL_set0_verify_cert_store(self.as_ptr(), cert_store.into_ptr()) as c_int)?; Ok(()) } } diff --git a/boring/src/x509/mod.rs b/boring/src/x509/mod.rs index b234bd2b..34896d6a 100644 --- a/boring/src/x509/mod.rs +++ b/boring/src/x509/mod.rs @@ -1584,9 +1584,7 @@ impl GeneralName { ffi::init(); let gn = cvt_p(ffi::GENERAL_NAME_new())?; (*gn).type_ = ffi::GEN_RID; - (*gn).d.registeredID = oid.as_ptr(); - - mem::forget(oid); + (*gn).d.registeredID = oid.into_ptr(); Ok(GeneralName::from_ptr(gn)) }