# HG changeset patch # User jbe # Date 1429043132 -7200 # Node ID df08e63dc44be4a2839e90965c4cfc163fc01cb3 # Parent ebaac38b722435164e3f4b8b75764f1de93baf84 Bugfix in close method of moonbridge_io (do not mark as closed before flushing) diff -r ebaac38b7224 -r df08e63dc44b moonbridge_io.c --- a/moonbridge_io.c Tue Apr 14 19:32:46 2015 +0200 +++ b/moonbridge_io.c Tue Apr 14 22:25:32 2015 +0200 @@ -433,23 +433,28 @@ moonbr_io_handle_t *handle; handle = luaL_checkudata(L, 1, MOONBR_IO_HANDLE_MT_REGKEY); if (handle->closed) luaL_error(L, "Attempt to close a closed I/O handle"); - handle->closed = 1; if (!reset) { if (handle->writeleft) { lua_pushcfunction(L, moonbr_io_flush); lua_pushvalue(L, 1); if (lua_pcall(L, 1, 2, 0)) { + handle->closed = 1; close(handle->fd); handle->fd = -1; lua_error(L); } + handle->closed = 1; if (!lua_toboolean(L, -2)) { close(handle->fd); handle->fd = -1; return 2; } + } else { + handle->closed = 1; + moonbr_io_handle_set_linger(L, handle, -1); } - moonbr_io_handle_set_linger(L, handle, -1); + } else { + handle->closed = 1; } if (handle->fd >= 0) { if (close(handle->fd)) {