Memory leak TCP server?
Posted: Fri Apr 29, 2016 3:01 pm
Hello. I have a TCP/http server with memory leaks, every page request eat memory until the crash "not enough memory"
i try with a simple example i still have that memory leaks.
bug? missed something?
I build the firmware with online tool (dev branch) two days ago.
i try with a simple example i still have that memory leaks.
bug? missed something?
I build the firmware with online tool (dev branch) two days ago.
Code: Select all
srv = net.createServer(net.TCP)
srv:listen(80, function(c)
c:on("receive", function(sck, pl)
local resp = {}
if (string.find(pl, "GET / HTTP/1.1") ~= nil
or string.find(pl, "GET /index.") ~= nil)
then
resp[#resp + 1] = "HTTP/1.1 200 OK\r\nContent-type: text/html\r\nServer: NodeMCU\r\nConnection: close\r\n\r\n"
elseif (string.find(pl, "GET /favicon.ico HTTP/1.1") ~= nil) then
resp[#resp + 1] = "HTTP/1.1 404 Not Found\r\nContent-type: text/html\r\nServer: NodeMCU\r\nConnection: close\r\n\r\n"
else
resp[#resp + 1] = "HTTP/1.1 200 OK\r\nContent-type: text/html\r\nServer: NodeMCU\r\nConnection: close\r\n\r\n"
end
local function send()
if #resp > 0
then sck:send(table.remove(resp, 1))
else
sck:close()
end
end
sck:on("sent", send)
send()
end)
end)