@@ -310,17 +310,21 @@ std::string ReadFile(uv_file file) {
310
310
uv_fs_t req;
311
311
char buffer_memory[4096 ];
312
312
uv_buf_t buf = uv_buf_init (buffer_memory, sizeof (buffer_memory));
313
+ int r;
314
+
313
315
do {
314
- uv_fs_read (uv_default_loop (),
315
- &req,
316
- file,
317
- &buf,
318
- 1 ,
319
- contents.length (), // offset
320
- nullptr );
321
- if (req.result <= 0 )
316
+ r = uv_fs_read (uv_default_loop (),
317
+ &req,
318
+ file,
319
+ &buf,
320
+ 1 ,
321
+ contents.length (), // offset
322
+ nullptr );
323
+ uv_fs_req_cleanup (&req);
324
+
325
+ if (r <= 0 )
322
326
break ;
323
- contents.append (buf.base , req. result );
327
+ contents.append (buf.base , r );
324
328
} while (true );
325
329
return contents;
326
330
}
@@ -337,20 +341,29 @@ Maybe<uv_file> CheckFile(const URL& search,
337
341
if (path.empty ()) {
338
342
return Nothing<uv_file>();
339
343
}
340
- uv_fs_open (nullptr , &fs_req, path.c_str (), O_RDONLY, 0 , nullptr );
341
- uv_file fd = fs_req.result ;
344
+
345
+ uv_file fd = uv_fs_open (nullptr , &fs_req, path.c_str (), O_RDONLY, 0 , nullptr );
346
+ uv_fs_req_cleanup (&fs_req);
347
+
342
348
if (fd < 0 ) {
343
349
return Nothing<uv_file>();
344
350
}
345
351
346
352
uv_fs_fstat (nullptr , &fs_req, fd, nullptr );
347
- if (fs_req.statbuf .st_mode & S_IFDIR) {
353
+ uint64_t is_directory = fs_req.statbuf .st_mode & S_IFDIR;
354
+ uv_fs_req_cleanup (&fs_req);
355
+
356
+ if (is_directory) {
348
357
uv_fs_close (nullptr , &fs_req, fd, nullptr );
358
+ uv_fs_req_cleanup (&fs_req);
349
359
return Nothing<uv_file>();
350
360
}
351
361
352
- if (opt == CLOSE_AFTER_CHECK)
362
+ if (opt == CLOSE_AFTER_CHECK) {
353
363
uv_fs_close (nullptr , &fs_req, fd, nullptr );
364
+ uv_fs_req_cleanup (&fs_req);
365
+ }
366
+
354
367
return Just (fd);
355
368
}
356
369
@@ -395,6 +408,7 @@ Maybe<URL> ResolveMain(Environment* env, const URL& search) {
395
408
std::string pkg_src = ReadFile (check.FromJust ());
396
409
uv_fs_t fs_req;
397
410
uv_fs_close (nullptr , &fs_req, check.FromJust (), nullptr );
411
+ uv_fs_req_cleanup (&fs_req);
398
412
399
413
// It's not okay for the called of this method to not be able to tell
400
414
// whether an exception is pending or not.
0 commit comments