@@ -310,17 +310,21 @@ std::string ReadFile(uv_file file) {
310310 uv_fs_t req;
311311 char buffer_memory[4096 ];
312312 uv_buf_t buf = uv_buf_init (buffer_memory, sizeof (buffer_memory));
313+ int r;
314+
313315 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 )
322326 break ;
323- contents.append (buf.base , req. result );
327+ contents.append (buf.base , r );
324328 } while (true );
325329 return contents;
326330}
@@ -337,20 +341,29 @@ Maybe<uv_file> CheckFile(const URL& search,
337341 if (path.empty ()) {
338342 return Nothing<uv_file>();
339343 }
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+
342348 if (fd < 0 ) {
343349 return Nothing<uv_file>();
344350 }
345351
346352 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) {
348357 uv_fs_close (nullptr , &fs_req, fd, nullptr );
358+ uv_fs_req_cleanup (&fs_req);
349359 return Nothing<uv_file>();
350360 }
351361
352- if (opt == CLOSE_AFTER_CHECK)
362+ if (opt == CLOSE_AFTER_CHECK) {
353363 uv_fs_close (nullptr , &fs_req, fd, nullptr );
364+ uv_fs_req_cleanup (&fs_req);
365+ }
366+
354367 return Just (fd);
355368}
356369
@@ -395,6 +408,7 @@ Maybe<URL> ResolveMain(Environment* env, const URL& search) {
395408 std::string pkg_src = ReadFile (check.FromJust ());
396409 uv_fs_t fs_req;
397410 uv_fs_close (nullptr , &fs_req, check.FromJust (), nullptr );
411+ uv_fs_req_cleanup (&fs_req);
398412
399413 // It's not okay for the called of this method to not be able to tell
400414 // whether an exception is pending or not.
0 commit comments