aboutsummaryrefslogtreecommitdiff
path: root/src/lfs.c
diff options
context:
space:
mode:
authorAlexey Melnichuk <mimir@newmail.ru>2014-01-08 16:18:31 +0300
committerAlexey Melnichuk <mimir@newmail.ru>2014-01-08 16:18:31 +0300
commitcc6007171bc30aaa2508d88bef58f40235ef1e63 (patch)
tree634cb3020db94077af9f94b3646582e3ab7964df /src/lfs.c
parent2b80db36f00dc3ac46724b1c128f734eecac181d (diff)
downloadluafilesystem-cc6007171bc30aaa2508d88bef58f40235ef1e63.tar.gz
luafilesystem-cc6007171bc30aaa2508d88bef58f40235ef1e63.tar.bz2
luafilesystem-cc6007171bc30aaa2508d88bef58f40235ef1e63.zip
Fix. Prevents double close the same handle (#24)
lfs_unlock_dir can be called multiple times for the same object. For example if lock:free is called manually. Then lfs_unlock_dir will be called always again, as soon as the LOCK_METATABLE is collected by GC. This can lead to strange file errors later on, like closing another file, which now has been assigned the same handle...
Diffstat (limited to 'src/lfs.c')
-rw-r--r--src/lfs.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/lfs.c b/src/lfs.c
index b7c4fcd..ccbba5e 100644
--- a/src/lfs.c
+++ b/src/lfs.c
@@ -281,7 +281,10 @@ static int lfs_lock_dir(lua_State *L) {
281} 281}
282static int lfs_unlock_dir(lua_State *L) { 282static int lfs_unlock_dir(lua_State *L) {
283 lfs_Lock *lock = luaL_checkudata(L, 1, LOCK_METATABLE); 283 lfs_Lock *lock = luaL_checkudata(L, 1, LOCK_METATABLE);
284 CloseHandle(lock->fd); 284 if(lock->fd != INVALID_HANDLE_VALUE) {
285 CloseHandle(lock->fd);
286 lock->fd=INVALID_HANDLE_VALUE;
287 }
285 return 0; 288 return 0;
286} 289}
287#else 290#else