ref: ba1476058afaffc3f24ca8fbde11234def04d1bf
parent: d7740736da8f2ca830d558cdedd89266b9019375
author: Frank Smit <frank@61924.nl>
date: Tue Jul 27 11:25:41 EDT 2021
lib/http: Free session and request when done.
--- a/lib/http/parse.myr
+++ b/lib/http/parse.myr
@@ -5,6 +5,7 @@
pkg http =
pkglocal const parsereq : (s : session# -> std.result(req#, err))
+ pkglocal const freereq : (r : req# -> void)
pkglocal const parseresp : (s : session#, r : resp# -> bool)
pkglocal const parsechunksz : (s : session# -> std.result(std.size, err))
pkglocal const parsenumber : (str : byte[:]#, base : int -> std.option(int))
@@ -70,9 +71,29 @@
std.slfree(ln)
;;
;;
+
-> `std.Ok std.mk(r)
:error
-> `std.Err err
+}
+
+const freereq = {r
+ for hdr : r.hdrs
+ std.slfree(hdr.0)
+ std.slfree(hdr.1)
+ ;;
+ std.slfree(r.hdrs)
+
+ for (k, v) : r.url.params
+ std.slfree(k)
+ std.slfree(v)
+ ;;
+ std.slfree(r.url.params)
+
+ std.slfree(r.url.host)
+ std.slfree(r.url.path)
+ std.free(r.url)
+ std.free(r)
}
const parseresp = {s, r : resp#
--- a/lib/http/server.myr
+++ b/lib/http/server.myr
@@ -41,23 +41,23 @@
var s
s = mksrvsession(fd)
+
while !srv.quit
match parsereq(s)
| `std.Ok req:
fn(srv, s, req)
- freereq(s)
+ freereq(req)
| `std.Err e:
break
;;
;;
+
+ freesession(s)
std.close(fd)
unref(srv)
}
const respond = {srv, s, resp
- var sb
-
- sb = std.mksb()
ioput(s, "HTTP/1.1 {} {}\r\n", resp.status, statusstr(resp.status))
if resp.enc != `Chunked
--- a/lib/http/session.myr
+++ b/lib/http/session.myr
@@ -47,6 +47,7 @@
bio.close(s.f)
std.slfree(s.host)
std.slfree(s.ua)
+ std.slfree(s.srvname)
std.free(s)
}