Skip to content

Commit

Permalink
Fix fd leak
Browse files Browse the repository at this point in the history
85108b3 introduced a regression, causing fd leaks

Closes #448
  • Loading branch information
mfussenegger committed Nov 4, 2023
1 parent 8d2bd9a commit 7746f95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lua/lint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,10 @@ function LintProc:publish(diagnostics)
if api.nvim_buf_is_valid(self.bufnr) and not self.cancelled then
vim.diagnostic.set(self.ns, self.bufnr, diagnostics)
end
self.stdout:shutdown(function()
self.stdout:close()
end)
self.stderr:shutdown(function()
self.stderr:close()
end)
self.stdout:shutdown()
self.stdout:close()
self.stderr:shutdown()
self.stderr:close()
end


Expand Down
11 changes: 11 additions & 0 deletions tests/compiler_spec.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
local function get_num_handles()
local pid = vim.fn.getpid()
local output = vim.fn.system({"lsof", "-p"}, tostring(pid))
local lines = vim.split(output, "\n", { plain = true })
return #lines
end

describe('compiler', function()
it('reads errors from both stdout and stderr', function()
local a = vim.api
Expand All @@ -6,9 +13,13 @@ describe('compiler', function()
a.nvim_buf_set_option(bufnr, 'errorformat', '%l: %m')
a.nvim_buf_set_option(bufnr, 'makeprg', 'python tests/both.py')

local handles = get_num_handles()
require('lint').try_lint('compiler')

vim.wait(5000, function() return next(vim.diagnostic.get(bufnr)) ~= nil end)

assert.are.same(handles, get_num_handles(), "shouldn't leak any handles")

local result = vim.diagnostic.get(bufnr)
for _, d in pairs(result) do
d.namespace = nil
Expand Down

0 comments on commit 7746f95

Please sign in to comment.