From b450d8771967d0848595f8e966972ada257d3ffb Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 12 Sep 2011 18:01:43 +0200 Subject: [PATCH] eio: fix memory leak in eio__scandir() --- src/unix/eio/eio.c | 12 +++++++++++- src/unix/fs.c | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/unix/eio/eio.c b/src/unix/eio/eio.c index a005db5d..74153ad1 100644 --- a/src/unix/eio/eio.c +++ b/src/unix/eio/eio.c @@ -1812,7 +1812,17 @@ eio__scandir (eio_req *req, etp_worker *self) #endif if (req->flags & EIO_FLAG_PTR1_FREE) - free (req->ptr1); + { + req->flags &= ~EIO_FLAG_PTR1_FREE; + free (req->ptr1); + req->ptr1 = NULL; + } + + if (!dirp) + { + req->errorno = errno; + return; + } req->flags |= EIO_FLAG_PTR1_FREE | EIO_FLAG_PTR2_FREE; req->ptr1 = dents = flags ? malloc (dentalloc * sizeof (eio_dirent)) : 0; diff --git a/src/unix/fs.c b/src/unix/fs.c index cab41064..60f5e59d 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -123,6 +123,8 @@ static int uv__fs_after(eio_req* eio) { * callback. We must keep it until uv_fs_req_cleanup. If we get rid of * libeio this can be avoided. */ + if (req->eio->ptr2 == NULL) + break; buflen = 0; name = req->eio->ptr2; for (i = 0; i < req->result; i++) {