diff --git a/actix-http/src/message.rs b/actix-http/src/message.rs index bccb4d53e..6c07e8993 100644 --- a/actix-http/src/message.rs +++ b/actix-http/src/message.rs @@ -353,14 +353,6 @@ impl Message { } } -impl Clone for Message { - fn clone(&self) -> Self { - Message { - head: self.head.clone(), - } - } -} - impl std::ops::Deref for Message { type Target = T; @@ -377,9 +369,7 @@ impl std::ops::DerefMut for Message { impl Drop for Message { fn drop(&mut self) { - if Rc::strong_count(&self.head) == 1 { - T::with_pool(|p| p.release(self.head.clone())) - } + T::with_pool(|p| p.release(self.head.clone())) } } @@ -416,9 +406,13 @@ impl std::ops::DerefMut for BoxedResponseHead { impl Drop for BoxedResponseHead { fn drop(&mut self) { - if let Some(head) = self.head.take() { - RESPONSE_POOL.with(move |p| p.release(head)) - } + RESPONSE_POOL.with(move |p| { + p.release( + self.head + .take() + .expect("ResponseHead is taken before dropped"), + ) + }) } }