fix unref default file descriptor while still in use

This commit is contained in:
devsaurus 2019-07-03 23:54:08 +02:00
parent 51912d5505
commit 1f1eeaf358
1 changed files with 5 additions and 4 deletions

View File

@ -123,15 +123,16 @@ static int file_close( lua_State* L )
ud = (file_fd_ud *)luaL_checkudata(L, 1, "file.obj"); ud = (file_fd_ud *)luaL_checkudata(L, 1, "file.obj");
} }
// unref default file descriptor
luaL_unref( L, LUA_REGISTRYINDEX, file_fd_ref );
file_fd_ref = LUA_NOREF;
if(ud->fd){ if(ud->fd){
vfs_close(ud->fd); vfs_close(ud->fd);
// mark as closed // mark as closed
ud->fd = 0; ud->fd = 0;
} }
// unref default file descriptor
luaL_unref( L, LUA_REGISTRYINDEX, file_fd_ref );
file_fd_ref = LUA_NOREF;
return 0; return 0;
} }