summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-27 14:30:15 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-27 14:30:15 +0800
commite33d11af96f3ea4ff11103ca74351506899f6c23 (patch)
tree43844ed8f7a2409511a0f93e7336904653d6445d /server
parent357564062f18bfd5eedad002fa55ff93db10833a (diff)
downloadlua-language-server-e33d11af96f3ea4ff11103ca74351506899f6c23.zip
修正编译出错导致的泄漏
Diffstat (limited to 'server')
-rw-r--r--server/src/vm/vm.lua21
1 files changed, 11 insertions, 10 deletions
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index 26fcc84a..ac642056 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -1150,15 +1150,7 @@ function mt:remove()
self.sources = nil
end
-local function compile(ast, lsp, uri)
- local vm = setmetatable({
- funcs = {},
- sources = {},
- main = nil,
- env = nil,
- lsp = lsp,
- uri = uri or '',
- }, mt)
+local function compile(vm, ast, lsp, uri)
-- 创建初始环境
ast.uri = vm.uri
@@ -1175,8 +1167,17 @@ return function (ast, lsp, uri)
if not ast then
return nil
end
- local suc, res = xpcall(compile, log.error, ast, lsp, uri)
+ local vm = setmetatable({
+ funcs = {},
+ sources = {},
+ main = nil,
+ env = nil,
+ lsp = lsp,
+ uri = uri or '',
+ }, mt)
+ local suc, res = xpcall(compile, log.error, vm, ast, lsp, uri)
if not suc then
+ vm:remove()
return nil, res
end
return res