Skip to content

Commit cfe9956

Browse files
committed
params/merge: fix lifetimes
1 parent 3b66877 commit cfe9956

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

openssl/src/params.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,18 @@ impl<'a> ParamsRef<'a> {
9494
/// Merges two `ParamsRef` objects into a new `Params` object.
9595
#[corresponds(OSSL_PARAM_merge)]
9696
#[allow(dead_code)]
97-
pub fn merge(&self, other: &ParamsRef<'a>) -> Result<Params<'a>, ErrorStack> {
98-
cvt_p(unsafe { ffi::OSSL_PARAM_merge(self.as_ptr(), other.as_ptr()) })
99-
.map(|p| unsafe { Params::from_ptr(p) })
97+
pub fn merge(&self, other: &ParamsRef<'_>) -> Result<Params<'a>, ErrorStack> {
98+
// OSSL_PARAM_merge shallow copies the params
99+
// OSSL_PARAM_free deep frees (so the params and values will be freed)
100+
// OSSL_PARAM_dup deep copies
101+
// Dupe both params[] so we don't end up pointing to freed memory.
102+
cvt_p(unsafe {
103+
ffi::OSSL_PARAM_merge(
104+
ffi::OSSL_PARAM_dup(self.as_ptr()),
105+
ffi::OSSL_PARAM_dup(other.as_ptr()),
106+
)
107+
})
108+
.map(|p| unsafe { Params::from_ptr(p) })
100109
}
101110

102111
/// Locate a parameter by the given key.

0 commit comments

Comments
 (0)