Skip to content

Commit

Permalink
src: plug trace file file descriptor leak
Browse files Browse the repository at this point in the history
Close existing file descriptors before overriding
the field with new ones.

Also, use `nullptr` as the loop for these synchronous
operations, since they do not run on the same thread
as the `uv_run()` call for the previously used loop.

PR-URL: #21867
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
  • Loading branch information
addaleax authored and targos committed Aug 1, 2018
1 parent 89e2302 commit ce48936
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/tracing/node_trace_writer.cc
Expand Up @@ -53,7 +53,7 @@ NodeTraceWriter::~NodeTraceWriter() {
uv_fs_t req;
int err;
if (fd_ != -1) {
err = uv_fs_close(tracing_loop_, &req, fd_, nullptr);
err = uv_fs_close(nullptr, &req, fd_, nullptr);
CHECK_EQ(err, 0);
uv_fs_req_cleanup(&req);
}
Expand Down Expand Up @@ -84,7 +84,12 @@ void NodeTraceWriter::OpenNewFileForStreaming() {
replace_substring(&filepath, "${pid}", std::to_string(uv_os_getpid()));
replace_substring(&filepath, "${rotation}", std::to_string(file_num_));

fd_ = uv_fs_open(tracing_loop_, &req, filepath.c_str(),
if (fd_ != -1) {
CHECK_EQ(uv_fs_close(nullptr, &req, fd_, nullptr), 0);
uv_fs_req_cleanup(&req);
}

fd_ = uv_fs_open(nullptr, &req, filepath.c_str(),
O_CREAT | O_WRONLY | O_TRUNC, 0644, nullptr);
uv_fs_req_cleanup(&req);
if (fd_ < 0) {
Expand Down

0 comments on commit ce48936

Please sign in to comment.