1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

examples: fix crash when running examples/ws/client.v outside of valgrind

This commit is contained in:
Delyan Angelov
2020-07-22 18:42:57 +03:00
parent b0d76c59f7
commit ebbc7bd471
4 changed files with 14 additions and 11 deletions

View File

@@ -239,13 +239,11 @@ pub fn (mut ws Client) close(code int, message string) {
}
}
// write will send the payload to the websocket server. NB: *it will not free the payload*, the caller is responsible for that.
pub fn (mut ws Client) write(payload byteptr, payload_len int, code OPCode) int {
mut bytes_written := -1
if ws.state != .open {
ws.send_error_event('WebSocket closed. Cannot write.')
unsafe {
free(payload)
}
return -1
}
header_len := 6 + if payload_len > 125 { 2 } else { 0 } + if payload_len > 0xffff { 6 } else { 0 }
@@ -305,7 +303,6 @@ pub fn (mut ws Client) write(payload byteptr, payload_len int, code OPCode) int
ws.log.debug('write: $bytes_written bytes written.')
free_data:
unsafe {
free(payload)
frame_buf.free()
header.free()
masking_key.free()