fix dealloc issues

This commit is contained in:
Martin Algesten
2018-10-23 20:18:24 +01:00
parent df7b5ca839
commit 2c9e62ad8c
3 changed files with 35 additions and 23 deletions

View File

@@ -89,19 +89,18 @@ impl<R: Read + Sized> PoolReturnRead<R> {
return;
}
let state = &mut unit.agent.lock().unwrap();
// bring back stream here to either go into pool or dealloc
let stream = unsafe { *Box::from_raw(self.stream) };
self.stream = ::std::ptr::null_mut();
if let Some(agent) = state.as_mut() {
unsafe {
let stream = *Box::from_raw(self.stream);
self.stream = ::std::ptr::null_mut();
if !stream.is_poolable() {
// just let it deallocate
return;
}
// insert back into pool
let key = PoolKey::new(&unit.url);
agent.pool().recycle.insert(key, stream);
if !stream.is_poolable() {
// just let it deallocate
return;
}
};
// insert back into pool
let key = PoolKey::new(&unit.url);
agent.pool().recycle.insert(key, stream);
}
}
}
@@ -124,3 +123,9 @@ impl<R: Read + Sized> Read for PoolReturnRead<R> {
Ok(amount)
}
}
impl<R: Read + Sized> Drop for PoolReturnRead<R> {
fn drop(&mut self) {
self.return_connection();
}
}