Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-03-14 23:47:35 +0300
committerJoyee Cheung <joyeec9h3@gmail.com>2018-03-19 02:25:55 +0300
commit897cec43c67d036f631e0538a8172a5a8f759611 (patch)
treef665bdf34ba3e777e32e98bbb16252be953e4725 /src/node_file.h
parent9c9324768f07051a34ca84154caa476082727cca (diff)
fs: fix memory leak in WriteString
In the async case, if the buffer was copied instead of being moved then the buf will not get deleted after the request is done. This was introduced when the FSReqWrap:: Ownership was removed in 4b9ba9b, and ReleaseEarly was no longer called upon destruction of FSReqWrap. Create a custom Init function so we can use the MaybeStackBuffer in the FSReqBase to copy the string in the async case. The data will then get destructed when the FSReqBase is destructed. Fixes: https://github.com/nodejs/node/issues/19356 PR-URL: https://github.com/nodejs/node/pull/19357 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_file.h')
-rw-r--r--src/node_file.h20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/node_file.h b/src/node_file.h
index fa373d46ad0..1925e400f2d 100644
--- a/src/node_file.h
+++ b/src/node_file.h
@@ -24,6 +24,8 @@ namespace fs {
class FSReqBase : public ReqWrap<uv_fs_t> {
public:
+ typedef MaybeStackBuffer<char, 64> FSReqBuffer;
+
FSReqBase(Environment* env, Local<Object> req, AsyncWrap::ProviderType type)
: ReqWrap(env, req, type) {
Wrap(object(), this);
@@ -34,9 +36,9 @@ class FSReqBase : public ReqWrap<uv_fs_t> {
}
void Init(const char* syscall,
- const char* data = nullptr,
- size_t len = 0,
- enum encoding encoding = UTF8) {
+ const char* data,
+ size_t len,
+ enum encoding encoding) {
syscall_ = syscall;
encoding_ = encoding;
@@ -49,6 +51,16 @@ class FSReqBase : public ReqWrap<uv_fs_t> {
}
}
+ FSReqBuffer& Init(const char* syscall, size_t len,
+ enum encoding encoding) {
+ syscall_ = syscall;
+ encoding_ = encoding;
+
+ buffer_.AllocateSufficientStorage(len + 1);
+ has_data_ = false; // so that the data does not show up in error messages
+ return buffer_;
+ }
+
virtual void FillStatsArray(const uv_stat_t* stat) = 0;
virtual void Reject(Local<Value> reject) = 0;
virtual void Resolve(Local<Value> value) = 0;
@@ -68,7 +80,7 @@ class FSReqBase : public ReqWrap<uv_fs_t> {
// Typically, the content of buffer_ is something like a file name, so
// something around 64 bytes should be enough.
- MaybeStackBuffer<char, 64> buffer_;
+ FSReqBuffer buffer_;
DISALLOW_COPY_AND_ASSIGN(FSReqBase);
};