Skip to content

Commit dab311a

Browse files
committed
unix: delay fs req register until after validation
On Unix, if a fs function fails validation after INIT but before sending the work to the thread pool, then is is necessary to manually unregister the request. This commit moves the registration to just before the work submission. This also makes Unix match the Windows behavior. Refs: libuv#1747 Refs: nodejs/node#18811 PR-URL: libuv#1751 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent e6168df commit dab311a

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

src/unix/fs.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@
6868
do { \
6969
if (req == NULL) \
7070
return UV_EINVAL; \
71-
req->type = UV_FS; \
72-
if (cb != NULL) \
73-
uv__req_init(loop, req, UV_FS); \
71+
UV_REQ_INIT(req, UV_FS); \
7472
req->fs_type = UV_FS_ ## subtype; \
7573
req->result = 0; \
7674
req->ptr = NULL; \
@@ -88,10 +86,8 @@
8886
req->path = path; \
8987
} else { \
9088
req->path = uv__strdup(path); \
91-
if (req->path == NULL) { \
92-
uv__req_unregister(loop, req); \
89+
if (req->path == NULL) \
9390
return UV_ENOMEM; \
94-
} \
9591
} \
9692
} \
9793
while (0)
@@ -107,10 +103,8 @@
107103
path_len = strlen(path) + 1; \
108104
new_path_len = strlen(new_path) + 1; \
109105
req->path = uv__malloc(path_len + new_path_len); \
110-
if (req->path == NULL) { \
111-
uv__req_unregister(loop, req); \
106+
if (req->path == NULL) \
112107
return UV_ENOMEM; \
113-
} \
114108
req->new_path = req->path + path_len; \
115109
memcpy((void*) req->path, path, path_len); \
116110
memcpy((void*) req->new_path, new_path, new_path_len); \
@@ -121,6 +115,7 @@
121115
#define POST \
122116
do { \
123117
if (cb != NULL) { \
118+
uv__req_register(loop, req); \
124119
uv__work_submit(loop, &req->work_req, uv__fs_work, uv__fs_done); \
125120
return 0; \
126121
} \
@@ -1288,11 +1283,8 @@ int uv_fs_mkdtemp(uv_loop_t* loop,
12881283
uv_fs_cb cb) {
12891284
INIT(MKDTEMP);
12901285
req->path = uv__strdup(tpl);
1291-
if (req->path == NULL) {
1292-
if (cb != NULL)
1293-
uv__req_unregister(loop, req);
1286+
if (req->path == NULL)
12941287
return UV_ENOMEM;
1295-
}
12961288
POST;
12971289
}
12981290

@@ -1329,11 +1321,8 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
13291321
if (nbufs > ARRAY_SIZE(req->bufsml))
13301322
req->bufs = uv__malloc(nbufs * sizeof(*bufs));
13311323

1332-
if (req->bufs == NULL) {
1333-
if (cb != NULL)
1334-
uv__req_unregister(loop, req);
1324+
if (req->bufs == NULL)
13351325
return UV_ENOMEM;
1336-
}
13371326

13381327
memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
13391328

@@ -1468,11 +1457,8 @@ int uv_fs_write(uv_loop_t* loop,
14681457
if (nbufs > ARRAY_SIZE(req->bufsml))
14691458
req->bufs = uv__malloc(nbufs * sizeof(*bufs));
14701459

1471-
if (req->bufs == NULL) {
1472-
if (cb != NULL)
1473-
uv__req_unregister(loop, req);
1460+
if (req->bufs == NULL)
14741461
return UV_ENOMEM;
1475-
}
14761462

14771463
memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
14781464

0 commit comments

Comments
 (0)