From 0ac2fdc55455794e057e4999a2e785ca8fbfb1b2 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 23 Aug 2012 00:32:56 +0200 Subject: [PATCH 1/2] unix: map errno ESPIPE --- include/uv.h | 5 +++-- src/unix/error.c | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/uv.h b/include/uv.h index 7c2c03f9..49160b2b 100644 --- a/include/uv.h +++ b/include/uv.h @@ -120,8 +120,9 @@ extern "C" { XX( 53, ENOTEMPTY, "directory not empty") \ XX( 54, ENOSPC, "no space left on device") \ XX( 55, EIO, "i/o error") \ - XX( 56, EROFS, "read-only file system" ) \ - XX( 57, ENODEV, "no such device" ) + XX( 56, EROFS, "read-only file system") \ + XX( 57, ENODEV, "no such device") \ + XX( 58, ESPIPE, "invalid seek") \ #define UV_ERRNO_GEN(val, name, s) UV_##name = val, diff --git a/src/unix/error.c b/src/unix/error.c index 9fbb312e..b2add994 100644 --- a/src/unix/error.c +++ b/src/unix/error.c @@ -68,6 +68,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) { case EAFNOSUPPORT: return UV_EAFNOSUPPORT; case EBADF: return UV_EBADF; case EPIPE: return UV_EPIPE; + case ESPIPE: return UV_ESPIPE; case EAGAIN: return UV_EAGAIN; #if EWOULDBLOCK != EAGAIN case EWOULDBLOCK: return UV_EAGAIN; From ad7b48aeec39ba90a9817aaf07abcaf3f9ebf462 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 25 Aug 2012 22:22:43 +0200 Subject: [PATCH 2/2] unix: fix memory leak in udp.c Some memory was leaked when the uv_udp_t handle was closed when there were in-flight send requests with a heap allocated buffer list. That doesn't happen much in practice. In the common case (writing < 5 buffers), the buffer list is stored inside the uv_udp_send_t structure, not allocated on the heap. --- src/unix/udp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/unix/udp.c b/src/unix/udp.c index 9f87060a..634d4a06 100644 --- a/src/unix/udp.c +++ b/src/unix/udp.c @@ -86,6 +86,10 @@ void uv__udp_finish_close(uv_udp_t* handle) { req = ngx_queue_data(q, uv_udp_send_t, queue); uv__req_unregister(handle->loop, req); + if (req->bufs != req->bufsml) + free(req->bufs); + req->bufs = NULL; + if (req->send_cb) { /* FIXME proper error code like UV_EABORTED */ uv__set_artificial_error(handle->loop, UV_EINTR); @@ -171,6 +175,7 @@ static void uv__udp_run_completed(uv_udp_t* handle) { if (req->bufs != req->bufsml) free(req->bufs); + req->bufs = NULL; if (req->send_cb == NULL) continue;