vweb: fix a leak

pull/5570/head
Alexander Medvednikov 2020-06-28 13:56:38 +02:00
parent b04e509830
commit 0138f46797
4 changed files with 27 additions and 4 deletions

View File

@ -115,6 +115,7 @@ pub fn (mut b Builder) str() string {
b.buf << `\0` b.buf << `\0`
s := string(b.buf,b.len) s := string(b.buf,b.len)
bis := b.initial_size bis := b.initial_size
//free(b.buf.data)
b.buf = []byte{cap: bis} b.buf = []byte{cap: bis}
b.len = 0 b.len = 0
return s return s

View File

@ -437,6 +437,17 @@ fn (mut g Gen) sub8_var(reg Register, var_offset int) {
g.println('sub8 $reg,DWORD PTR[rbp-$var_offset.hex2()]') g.println('sub8 $reg,DWORD PTR[rbp-$var_offset.hex2()]')
} }
fn (mut g Gen) mul8_var(reg Register, var_offset int) {
g.write8(0x0f)
g.write8(0xaf)
match reg {
.eax, .rax { g.write8(0x45) }
else { verror('mul8_var') }
}
g.write8(0xff - var_offset + 1)
g.println('mul8 $reg,DWORD PTR[rbp-$var_offset.hex2()]')
}
fn (mut g Gen) leave() { fn (mut g Gen) leave() {
g.write8(0xc9) g.write8(0xc9)
g.println('leave') g.println('leave')
@ -732,6 +743,7 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) {
var_offset := g.get_var_offset(ident.name) var_offset := g.get_var_offset(ident.name)
match node.op { match node.op {
.plus { g.add8_var(.eax, var_offset) } .plus { g.add8_var(.eax, var_offset) }
.mul { g.mul8_var(.eax, var_offset) }
.minus { g.sub8_var(.eax, var_offset) } .minus { g.sub8_var(.eax, var_offset) }
else {} else {}
} }

View File

@ -11,11 +11,19 @@ fn print_number(n int) {
if n == 9 { println('9') } if n == 9 { println('9') }
} }
struct User {
age int
}
fn print_user(u User) {
}
fn test_add() { fn test_add() {
println('test_add()') println('test_add()')
x := 2 x := 2
y := 3 y :=3
z := x + y z := x * y
q := y - x q := y - x
print_number(x) print_number(x)
print_number(y) print_number(y)
@ -26,5 +34,5 @@ fn test_add() {
fn main() { fn main() {
println('start') println('start')
test_add() test_add()
println('end') println('end1l')
} }

View File

@ -58,6 +58,7 @@ fn (mut ctx Context) send_response_to_client(mimetype string, res string) bool {
if ctx.done { return false } if ctx.done { return false }
ctx.done = true ctx.done = true
mut sb := strings.new_builder(1024) mut sb := strings.new_builder(1024)
defer { sb.free() }
sb.write('HTTP/1.1 200 OK\r\nContent-Type: ') sb.write(mimetype) sb.write('HTTP/1.1 200 OK\r\nContent-Type: ') sb.write(mimetype)
sb.write('\r\nContent-Length: ') sb.write(res.len.str()) sb.write('\r\nContent-Length: ') sb.write(res.len.str())
sb.write(ctx.headers) sb.write(ctx.headers)
@ -65,7 +66,7 @@ fn (mut ctx Context) send_response_to_client(mimetype string, res string) bool {
sb.write(headers_close) sb.write(headers_close)
sb.write(res) sb.write(res)
ctx.conn.send_string(sb.str()) or { return false } ctx.conn.send_string(sb.str()) or { return false }
sb.free() //sb.free()
return true return true
} }
@ -304,6 +305,7 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
return return
} }
app.vweb.send_response_to_client(mime_type, data) app.vweb.send_response_to_client(mime_type, data)
data.free()
return return
} }