mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Avoid unlocking the response body while it is in an inconsistent state.
This commit is contained in:
parent
be896712ac
commit
8a4a5c0cb5
1 changed files with 6 additions and 8 deletions
|
@ -42,7 +42,7 @@ use std::collections::HashSet;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use std::mem::swap;
|
use std::mem;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
@ -1101,16 +1101,14 @@ fn http_network_fetch(request: Rc<Request>,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ok(Data::Done) | Err(_) => {
|
Ok(Data::Done) | Err(_) => {
|
||||||
let mut empty_vec = Vec::new();
|
let mut body = res_body.lock().unwrap();
|
||||||
let completed_body = match *res_body.lock().unwrap() {
|
let completed_body = match *body {
|
||||||
ResponseBody::Receiving(ref mut body) => {
|
ResponseBody::Receiving(ref mut body) => {
|
||||||
// avoid cloning the body
|
mem::replace(body, vec![])
|
||||||
swap(body, &mut empty_vec);
|
|
||||||
empty_vec
|
|
||||||
},
|
},
|
||||||
_ => empty_vec,
|
_ => vec![],
|
||||||
};
|
};
|
||||||
*res_body.lock().unwrap() = ResponseBody::Done(completed_body);
|
*body = ResponseBody::Done(completed_body);
|
||||||
let _ = done_sender.send(Data::Done);
|
let _ = done_sender.send(Data::Done);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue