From ad7b48aeec39ba90a9817aaf07abcaf3f9ebf462 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 25 Aug 2012 22:22:43 +0200 Subject: [PATCH] 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;