Skip to content

Commit 85c8540

Browse files
committed
Fix shutdown
1 parent 2be811b commit 85c8540

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/imp/mbedtls.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ unsafe impl<S> Send for TlsStream<S> {}
174174
impl<S> Drop for TlsStream<S> {
175175
fn drop(&mut self) {
176176
unsafe {
177-
Box::from_raw(self.session);
177+
if self.session != ::std::ptr::null_mut() {
178+
Box::from_raw(self.session);
179+
}
178180
Box::from_raw(self.socket);
179181

180182
Box::from_raw(self.ctx);
@@ -426,6 +428,8 @@ impl<S> TlsStream<S> {
426428
}
427429

428430
pub fn tls_server_end_point(&self) -> Result<Option<Vec<u8>>, Error> {
431+
// FIXME need to take server certificate in all cases, not always peer cert
432+
// so this is broken for servers
429433
let cert = match self.peer_certificate()? {
430434
Some(cert) => cert,
431435
None => return Ok(None),
@@ -448,6 +452,10 @@ impl<S> TlsStream<S> {
448452

449453
pub fn shutdown(&mut self) -> io::Result<()> {
450454
// Shutdown happens as a result of drop ...
455+
unsafe {
456+
Box::from_raw(self.session);
457+
self.session = ::std::ptr::null_mut();
458+
}
451459
Ok(())
452460
}
453461
}

0 commit comments

Comments
 (0)