Skip to content

Commit

Permalink
autofree: free global map consts and some vweb fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Mar 17, 2021
1 parent b4f7a97 commit 091a1ba
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions vlib/net/http/header.v
Expand Up @@ -325,6 +325,12 @@ mut:
data map[string][]string
}

pub fn (mut h Header) free() {
unsafe {
h.data.free()
}
}

pub struct HeaderConfig {
key CommonHeader
value string
Expand Down
6 changes: 5 additions & 1 deletion vlib/v/gen/c/cgen.v
Expand Up @@ -4642,12 +4642,16 @@ fn (mut g Gen) const_decl_init_later(mod string, name string, val string, typ ta
}
}
if g.is_autofree {
sym := g.table.get_type_symbol(typ)
if styp.starts_with('Array_') {
g.cleanups[mod].writeln('\tarray_free(&$cname);')
}
if styp == 'string' {
else if styp == 'string' {
g.cleanups[mod].writeln('\tstring_free(&$cname);')
}
else if sym.kind == .map {
g.cleanups[mod].writeln('\tmap_free(&$cname);')
}
}
}

Expand Down
1 change: 1 addition & 0 deletions vlib/vweb/request.v
Expand Up @@ -38,6 +38,7 @@ fn parse_request(mut reader io.BufferedReader) ?http.Request {
reader.read(mut body) or {}
}
}
h.free()

return http.Request{
method: method
Expand Down
2 changes: 2 additions & 0 deletions vlib/vweb/vweb.v
Expand Up @@ -298,6 +298,8 @@ pub fn run_app<T>(mut app T, port int) {
}
}


[manualfree]
fn handle_conn<T>(mut conn net.TcpConn, mut app T) {
conn.set_read_timeout(30 * time.second)
conn.set_write_timeout(30 * time.second)
Expand Down

0 comments on commit 091a1ba

Please sign in to comment.