nvim-tree/nvim-tree.lua

utils.read_file may hold onto fd

Closed this issue · 1 comments

Description

require('nvim-tree.utils').read_file does not close fd if stat is falsy, potentially leaving hanging file descriptors.

Neovim version

NVIM v0.12.0-dev-582e071-dirty
Build type: Release
LuaJIT 2.1.1731601260

Operating system and version

Linux 6.6.87.2-microsoft-standard-WSL2

Windows variant

WSL

nvim-tree version

master

Clean room replication

vim.pack.add({ 'https://github.com/nvim-tree/nvim-tree.lua' }, { load = true })

Steps to reproduce

  1. nvim
  2. Do anything that makes nvim-tree.lua call require('nvim-tree.utils').read_file
  3. On the off chance that it fails to fstat(2), it leaves a hanging file descriptor

Expected behavior

require('nvim-tree.utils').read_file calls vim.loop.fs_close(fd) prior to returning, if stat is falsy.

Actual behavior

require('nvim-tree.utils').read_file does not call vim.loop.fs_close(fd) prior to returning, when stat is falsy.

Let's remove that function, PR in progress.