io: BufferedReader.free()

pull/9325/head
Alexander Medvednikov 2021-03-15 21:25:19 +01:00
parent 667a26335f
commit 852d302b87
2 changed files with 9 additions and 0 deletions

View File

@ -55,6 +55,12 @@ pub fn (mut r BufferedReader) read(mut buf []byte) ?int {
return read return read
} }
pub fn (mut r BufferedReader) free() {
unsafe {
r.buf.free()
}
}
// fill_buffer attempts to refill the internal buffer // fill_buffer attempts to refill the internal buffer
// and returns whether it got any data // and returns whether it got any data
fn (mut r BufferedReader) fill_buffer() bool { fn (mut r BufferedReader) fill_buffer() bool {

View File

@ -305,6 +305,9 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T) {
conn.close() or {} conn.close() or {}
} }
mut reader := io.new_buffered_reader(reader: io.make_reader(conn)) mut reader := io.new_buffered_reader(reader: io.make_reader(conn))
defer {
reader.free()
}
page_gen_start := time.ticks() page_gen_start := time.ticks()
req := parse_request(mut reader) or { req := parse_request(mut reader) or {
eprintln('error parsing request: $err') eprintln('error parsing request: $err')