Skip to content

Commit 9f4d7a9

Browse files
Fractal147marcoskirsch
authored andcommitted
Fixed unnecessary globals as in issue #113. (#122)
* Fixed global assignment that should be local Made result variable be local, see Issue #113 * Made global variable local Made ASCII variable be local, see Issue #113 * Made more variables local Related to Issue #113. questionMarkPos, and b,c,d,e,f all are global in scope, and are not cleared from memory, so leak. Frankly, b, c, d, e, and f are not used either, but will now get GC'd later, if they ever were assigned, so not problematic line 114 also has _ and i to make local too, so were put on their own line. i on line 24 also was unnecessarily global, and undetected in issue #113 * Made module more local Made the basicAuth table local in scope. Since it is returned when dofile is called in httpserver.lua, that already has a correctly scoped table, 'auth'. This is related to issue #113, and should reduce memory loss to globals * Made bufferedConnection local bufferedConnection was global and didn't have to be. Part of issue #113. Now no longer remains in _G (globals table) after a connection has closed.
1 parent 7c8fe9c commit 9f4d7a9

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

httpserver-b64decode.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ end
3737

3838
-- logic OR for number values
3939
local function lor(x,y)
40-
result = 0
40+
local result = 0
4141
for p=1,8 do result = result + (((bit(x,p) or bit(y,p)) == true) and uipow(2, (p-1)) or 0) end
4242
return result
4343
end
4444

4545
-- Character decoding table
4646
local function toBase64Byte(char)
47-
ascii = string.byte(char, 1)
47+
local ascii = string.byte(char, 1)
4848
if ascii >= string.byte('A', 1) and ascii <= string.byte('Z', 1) then return ascii - string.byte('A', 1)
4949
elseif ascii >= string.byte('a', 1) and ascii <= string.byte('z', 1) then return ascii - string.byte('a', 1) + 26
5050
elseif ascii >= string.byte('0', 1) and ascii <= string.byte('9', 1) then return ascii + 4

httpserver-basicauth.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-- Part of nodemcu-httpserver, authenticates a user using http basic auth.
33
-- Author: Sam Dieck
44

5-
basicAuth = {}
5+
local basicAuth = {}
66

77
-- Returns true if the user/password match one of the users/passwords in httpserver-conf.lua.
88
-- Returns false otherwise.

httpserver-connection.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
-- flush() and for closing the connection.
66
-- Author: Philip Gladstone, Marcos Kirsch
77

8-
BufferedConnection = {}
8+
local BufferedConnection = {}
99

1010
-- parameter is the nodemcu-firmware connection
1111
function BufferedConnection:new(connection)

httpserver-request.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ local function uri_decode(input)
2121
end
2222

2323
local function parseArgs(args)
24-
local r = {}; i=1
24+
local r = {}
25+
local i = 1
2526
if args == nil or args == "" then return r end
2627
for arg in string.gmatch(args, "([^&]+)") do
2728
local name, value = string.match(arg, "(.*)=(.*)")
@@ -83,7 +84,7 @@ local function parseUri(uri)
8384

8485
if uri == nil then return r end
8586
if uri == "/" then uri = "/index.html" end
86-
questionMarkPos, b, c, d, e, f = uri:find("?")
87+
local questionMarkPos, b, c, d, e, f = uri:find("?")
8788
if questionMarkPos == nil then
8889
r.file = uri:sub(1, questionMarkPos)
8990
r.args = {}
@@ -115,6 +116,7 @@ return function (request)
115116
if not e then return nil end
116117
local line = request:sub(1, e - 1)
117118
local r = {}
119+
local _, i
118120
_, i, r.method, r.request = line:find("^([A-Z]+) (.-) HTTP/[1-9]+.[0-9]+$")
119121
if not (r.method and r.request) then
120122
--print("invalid request: ")

0 commit comments

Comments
 (0)