diff options
| author | Alexey Melnichuk <mimir@newmail.ru> | 2014-01-08 16:18:31 +0300 |
|---|---|---|
| committer | Alexey Melnichuk <mimir@newmail.ru> | 2014-01-08 16:18:31 +0300 |
| commit | cc6007171bc30aaa2508d88bef58f40235ef1e63 (patch) | |
| tree | 634cb3020db94077af9f94b3646582e3ab7964df | |
| parent | 2b80db36f00dc3ac46724b1c128f734eecac181d (diff) | |
| download | luafilesystem-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...
| -rw-r--r-- | src/lfs.c | 5 |
1 files changed, 4 insertions, 1 deletions
| @@ -281,7 +281,10 @@ static int lfs_lock_dir(lua_State *L) { | |||
| 281 | } | 281 | } |
| 282 | static int lfs_unlock_dir(lua_State *L) { | 282 | static 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 |
