New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua function utils.readdir() leaks file descriptors #4045

martinvonwittich opened this Issue Jan 16, 2017 · 0 comments


None yet
1 participant

martinvonwittich commented Jan 16, 2017

mpv version and platform

martin@martin ~ % mpv --version
mpv 0.14.0 (C) 2000-2015 mpv/MPlayer/mplayer2 projects
 built on UNKNOWN
ffmpeg library versions:
   libavutil       54.31.100
   libavcodec      56.60.100
   libavformat     56.40.101
   libswscale      3.1.101
   libavfilter     5.40.101
   libswresample   1.2.101
ffmpeg version: 2.8.10-0ubuntu0.16.04.1

If you're not using git master or the latest release, update.

Hm, my version seems to be pretty old, but I'm also pretty lazy and as far as I can tell from the source code ( ) the bug doesn't seem to be fixed in HEAD yet.

Reproduction steps

Create an empty folder:

mkdir x

Create the following Lua script and name it "readdir-bug.lua":

local utils = require("mp.utils")

local success = 0
local fail = 0

for i = 1,1024 do
  local files = utils.readdir("x", "files")

  if (files ~= nil) then
    success = success + 1
    fail = fail + 1

print("success: " .. success .. " fail: " .. fail)

Run the script:

martin@martin ~ % mpv --script readdir-bug.lua /dev/null 
[readdir_bug] success: 1018 fail: 6 
Playing: /dev/null
[file] Cannot open file '/dev/null': Too many open files
Failed to open /dev/null.

Exiting... (Errors when loading file)

Expected behavior

The script should call utils.readdir() 1024 times successfully, and the final error message should be "Playing: /dev/null\nFailed to recognize file format." like this:

martin@martin ~ % mpv /dev/null                        
Playing: /dev/null
Failed to recognize file format.

Exiting... (Errors when loading file)

Actual behavior

The script only manages to call utils.readdir() 1018 times successfully; then the file descriptors of the mpv process are exhausted, and the remaining 6 calls fail. After that, mpv is unable to open any further files, so it even fails to open /dev/null. The reason is probably a missing closedir() call in the function script_readdir() in player/lua.c.

woodruffw added a commit to woodruffw-forks/mpv that referenced this issue Jan 16, 2017

@wm4 wm4 closed this in a4cdd8b Jan 17, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment