1
0
Fork 0
forked from wry/wry

all: fix memory leaks

This commit is contained in:
Julian Orth 2022-05-02 22:11:59 +02:00
parent e212e0b8b1
commit 9904717c71
18 changed files with 149 additions and 10 deletions

View file

@ -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();
}
}