Skip to content

Commit

Permalink
Fix UB: Non-static callbacks are unsound
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Nov 11, 2023
1 parent 0461f65 commit 4207a9c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/ws/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ impl EspWebSocketClient {
}
}

impl<'a> Drop for EspWebSocketClient<'a> {
impl Drop for EspWebSocketClient {
fn drop(&mut self) {
esp!(unsafe { esp_websocket_client_close(self.handle, self.timeout) }).unwrap();
esp!(unsafe { esp_websocket_client_destroy(self.handle) }).unwrap();
Expand All @@ -542,22 +542,22 @@ impl<'a> Drop for EspWebSocketClient<'a> {
}
}

impl<'a> RawHandle for EspWebSocketClient<'a> {
impl RawHandle for EspWebSocketClient {
type Handle = esp_websocket_client_handle_t;

fn handle(&self) -> Self::Handle {
self.handle
}
}

impl<'a> ErrorType for EspWebSocketClient<'a> {
impl ErrorType for EspWebSocketClient {
type Error = EspIOError;
}

impl<'a> Sender for EspWebSocketClient<'a> {
impl Sender for EspWebSocketClient {
fn send(&mut self, frame_type: FrameType, frame_data: &[u8]) -> Result<(), Self::Error> {
EspWebSocketClient::send(self, frame_type, frame_data).map_err(EspIOError)
}
}

unsafe impl<'a> Send for EspWebSocketClient<'a> {}
unsafe impl Send for EspWebSocketClient {}

0 comments on commit 4207a9c

Please sign in to comment.