Skip to content

Commit 7fd35e6

Browse files
committed
uv: apply floating patch 2f54947b
1 parent c5f5d4c commit 7fd35e6

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

deps/uv/src/unix/fs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,15 @@ static ssize_t uv__fs_readdir(uv_fs_t* req) {
312312
dents = NULL;
313313
n = scandir(req->path, &dents, uv__fs_readdir_filter, alphasort);
314314

315+
/* NOTE: We will use nbufs as an index field */
316+
req->nbufs = 0;
317+
315318
if (n == 0)
316319
goto out; /* osx still needs to deallocate some memory */
317320
else if (n == -1)
318321
return n;
319322

320-
/* NOTE: We will use nbufs as an index field */
321323
req->ptr = dents;
322-
req->nbufs = 0;
323324

324325
return n;
325326

@@ -334,6 +335,8 @@ static ssize_t uv__fs_readdir(uv_fs_t* req) {
334335
}
335336
errno = saved_errno;
336337

338+
req->ptr = NULL;
339+
337340
return n;
338341
}
339342

deps/uv/test/test-fs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,13 @@ static void readdir_cb(uv_fs_t* req) {
436436

437437

438438
static void empty_readdir_cb(uv_fs_t* req) {
439+
uv_dirent_t dent;
440+
439441
ASSERT(req == &readdir_req);
440442
ASSERT(req->fs_type == UV_FS_READDIR);
441443
ASSERT(req->result == 0);
442444
ASSERT(req->ptr == NULL);
445+
ASSERT(UV_EOF == uv_fs_readdir_next(req, &dent));
443446
uv_fs_req_cleanup(req);
444447
readdir_cb_count++;
445448
}
@@ -1805,6 +1808,7 @@ TEST_IMPL(fs_stat_missing_path) {
18051808
TEST_IMPL(fs_readdir_empty_dir) {
18061809
const char* path;
18071810
uv_fs_t req;
1811+
uv_dirent_t dent;
18081812
int r;
18091813

18101814
path = "./empty_dir/";
@@ -1813,10 +1817,14 @@ TEST_IMPL(fs_readdir_empty_dir) {
18131817
uv_fs_mkdir(loop, &req, path, 0777, NULL);
18141818
uv_fs_req_cleanup(&req);
18151819

1820+
/* Fill the req to ensure that required fields are cleaned up */
1821+
memset(&req, 0xdb, sizeof(req));
1822+
18161823
r = uv_fs_readdir(loop, &req, path, 0, NULL);
18171824
ASSERT(r == 0);
18181825
ASSERT(req.result == 0);
18191826
ASSERT(req.ptr == NULL);
1827+
ASSERT(UV_EOF == uv_fs_readdir_next(&req, &dent));
18201828
uv_fs_req_cleanup(&req);
18211829

18221830
r = uv_fs_readdir(loop, &readdir_req, path, 0, empty_readdir_cb);

0 commit comments

Comments
 (0)