diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-07-18 02:20:51 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-08-01 17:16:55 +0200 |
commit | 5c212a61d10fd96cc3cc00c632f6bf5cd44ffc9d (patch) | |
tree | 2a08b64b57658fdd5314d62b34c3a79a696009ca /src/tracing | |
parent | 1f5aa5a23c5868eb42b673f3efe65912d445ac18 (diff) | |
download | android-node-v8-5c212a61d10fd96cc3cc00c632f6bf5cd44ffc9d.tar.gz android-node-v8-5c212a61d10fd96cc3cc00c632f6bf5cd44ffc9d.tar.bz2 android-node-v8-5c212a61d10fd96cc3cc00c632f6bf5cd44ffc9d.zip |
src: plug trace file file descriptor leak
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: https://github.com/nodejs/node/pull/21867
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Diffstat (limited to 'src/tracing')
-rw-r--r-- | src/tracing/node_trace_writer.cc | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/tracing/node_trace_writer.cc b/src/tracing/node_trace_writer.cc index 2fdb929723..2fb7c12a82 100644 --- a/src/tracing/node_trace_writer.cc +++ b/src/tracing/node_trace_writer.cc @@ -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); } @@ -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) { |