From 248ca5d61283b98066828cb522adaf4c7187f570 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 3 Dec 2011 23:31:02 +0100 Subject: [PATCH 1/4] unix: translate ETIMEDOUT to UV_ETIMEDOUT --- src/unix/error.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unix/error.c b/src/unix/error.c index 5f43709d..e904d390 100644 --- a/src/unix/error.c +++ b/src/unix/error.c @@ -82,6 +82,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) { case EHOSTUNREACH: return UV_EHOSTUNREACH; case EAI_NONAME: return UV_ENOENT; case ESRCH: return UV_ESRCH; + case ETIMEDOUT: return UV_ETIMEDOUT; default: return UV_UNKNOWN; } From 34e95d1a4cd19051464a18f8c106b43e2053ae99 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 4 Dec 2011 13:20:21 +0100 Subject: [PATCH 2/4] unix: make it safe to delete the default loop Fixes a potential free() of non-malloc'ed memory. --- src/unix/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/unix/core.c b/src/unix/core.c index 7978e1bb..91150360 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -169,7 +169,15 @@ uv_loop_t* uv_loop_new(void) { void uv_loop_delete(uv_loop_t* loop) { uv_ares_destroy(loop, loop->channel); ev_loop_destroy(loop->ev); - free(loop); + +#ifndef NDEBUG + memset(loop, 0, sizeof *loop); +#endif + + if (loop == default_loop_ptr) + default_loop_ptr = NULL; + else + free(loop); } From 0db3274f8af73b9d8a7757f7fdc699e7f7f92349 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 5 Dec 2011 16:56:28 +0100 Subject: [PATCH 3/4] unix: check UV_CLOSING flag in uv__write() uv__write() runs after the read callbacks have fired. Said callbacks may have closed the handle, handle that graciously. --- src/unix/stream.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/unix/stream.c b/src/unix/stream.c index 25737814..035e6383 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -341,6 +341,13 @@ static void uv__write(uv_stream_t* stream) { int iovcnt; ssize_t n; + if (stream->flags & UV_CLOSING) { + /* Handle was closed this tick. We've received a stale + * 'is writable' callback from the event loop, ignore. + */ + return; + } + start: assert(stream->fd >= 0); From b89c31b93632dcbc03bb4a46f06e47444ce8e9c3 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 6 Dec 2011 22:20:30 +0100 Subject: [PATCH 4/4] unix: fix warning: return 0 in function returning void --- src/unix/pipe.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/unix/pipe.c b/src/unix/pipe.c index 43869b63..5509136a 100644 --- a/src/unix/pipe.c +++ b/src/unix/pipe.c @@ -274,5 +274,4 @@ void uv__pipe_accept(EV_P_ ev_io* watcher, int revents) { void uv_pipe_pending_instances(uv_pipe_t* handle, int count) { - return 0; }