Browse Source

httpserver: fix memory leak

There was a memory leak related to not dropping all references to
fifosock's ssend.
Jedrzej Potoniec 3 years ago
parent
commit
9e08be7b28
1 changed files with 9 additions and 6 deletions
  1. 9 6
      lua_modules/http/httpserver.lua

+ 9 - 6
lua_modules/http/httpserver.lua

@@ -86,19 +86,22 @@ do
       local buf = ""
       local method, url
 
+      local ondisconnect = function(connection)
+        connection:on("receive", nil)
+        connection:on("disconnection", nil)
+        connection:on("sent", nil)
+        collectgarbage("collect")
+      end
+
       local cfini = function()
-        conn:on("receive", nil)
-        conn:on("disconnection", nil)
         csend(function()
           conn:on("sent", nil)
           conn:close()
+          ondisconnect(conn)
         end)
       end
 
-      local ondisconnect = function(connection)
-        connection:on("sent", nil)
-        collectgarbage("collect")
-      end
+
       -- header parser
       local cnt_len = 0