diff --git a/lib/g3-openssl/src/async_job/task.rs b/lib/g3-openssl/src/async_job/task.rs index 3bc01bff..e0d5327a 100644 --- a/lib/g3-openssl/src/async_job/task.rs +++ b/lib/g3-openssl/src/async_job/task.rs @@ -72,6 +72,26 @@ pub struct OpensslAsyncTask { action: Box>>, } +impl Drop for OpensslAsyncTask { + fn drop(&mut self) { + if !self.job.is_null() { + let mut ret: c_int = 0; + + // reset ctx in job to be null before we drop it + unsafe { + ffi::ASYNC_start_job( + &mut self.job, + ptr::null_mut(), + &mut ret, + None, // ignored + ptr::null_mut(), // ignored + 0, // ignored + ) + }; + } + } +} + /// NOTE: OpensslAsyncTask in fact is not Send, /// make sure you call it in a single threaded async runtime unsafe impl Send for OpensslAsyncTask {} @@ -241,6 +261,8 @@ where type Output = Result; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - self.get_mut().poll_run(cx) + let r = ready!(self.get_mut().poll_run(cx)); + self.job = ptr::null_mut(); // reset + Poll::Ready(r) } }