all: fix memory leaks
This commit is contained in:
parent
e212e0b8b1
commit
9904717c71
18 changed files with 149 additions and 10 deletions
|
|
@ -61,7 +61,7 @@ unsafe extern "C" fn unref(data: *const u8) {
|
|||
}
|
||||
|
||||
unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) {
|
||||
let _tc = &*data.cast::<TestConfig>();
|
||||
let tc = &*data.cast::<TestConfig>();
|
||||
let msg = std::slice::from_raw_parts(msg, size);
|
||||
let res = bincode::decode_from_slice::<ServerMessage, _>(msg, bincode_ops());
|
||||
let (msg, _) = match res {
|
||||
|
|
@ -83,6 +83,7 @@ unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) {
|
|||
ServerMessage::DelConnector { .. } => {}
|
||||
ServerMessage::TimerExpired { .. } => {}
|
||||
ServerMessage::GraphicsInitialized => {}
|
||||
ServerMessage::Clear => tc.clear(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -114,10 +115,8 @@ impl TestConfig {
|
|||
pub fn quit(&self) -> Result<(), TestError> {
|
||||
self.send(ClientMessage::Quit)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TestConfig {
|
||||
fn drop(&mut self) {
|
||||
fn clear(&self) {
|
||||
unsafe {
|
||||
if let Some(srv) = self.srv.take() {
|
||||
(srv.srv_unref)(srv.srv_data);
|
||||
|
|
@ -125,3 +124,9 @@ impl Drop for TestConfig {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TestConfig {
|
||||
fn drop(&mut self) {
|
||||
self.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue