From d251dee33b0935ffbdcd94f4126870883aaac140 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Sat, 7 Jan 2017 20:45:55 +0100 Subject: [PATCH] fs: cleanup uv__fs_scandir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `out` section is only reachable now if `scandir` returns 0. PR-URL: https://github.com/libuv/libuv/pull/1189 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Saúl Ibarra Corretgé --- src/unix/fs.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/unix/fs.c b/src/unix/fs.c index e047b671..f9513ea5 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -380,7 +380,6 @@ static int uv__fs_scandir_sort(UV_CONST_DIRENT** a, UV_CONST_DIRENT** b) { static ssize_t uv__fs_scandir(uv_fs_t* req) { uv__dirent_t **dents; - int saved_errno; int n; dents = NULL; @@ -389,29 +388,18 @@ static ssize_t uv__fs_scandir(uv_fs_t* req) { /* NOTE: We will use nbufs as an index field */ req->nbufs = 0; - if (n == 0) - goto out; /* osx still needs to deallocate some memory */ - else if (n == -1) + if (n == 0) { + /* OS X still needs to deallocate some memory. + * Memory was allocated using the system allocator, so use free() here. + */ + free(dents); + dents = NULL; + } else if (n == -1) { return n; + } req->ptr = dents; - return n; - -out: - saved_errno = errno; - if (dents != NULL) { - int i; - - /* Memory was allocated using the system allocator, so use free() here. */ - for (i = 0; i < n; i++) - free(dents[i]); - free(dents); - } - errno = saved_errno; - - req->ptr = NULL; - return n; }