GeezerVison is showing github.com — src: plug memory leaks · tcper/node@6457746
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/node_buffer.h +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -67,12 +67,17 @@ static inline bool IsWithinBounds(size_t off, size_t len, size_t max) { | 67 | 67 | // in src/node_internals.h because of a circular dependency. | 68 | 68 | #if defined(NODE_WANT_INTERNALS) | 69 | 69 | v8::MaybeLocal<v8::Object> New(Environment* env, size_t size); | | 70 | +// Makes a copy of |data|. | 70 | 71 | v8::MaybeLocal<v8::Object> New(Environment* env, const char* data, size_t len); | | 72 | +// Takes ownership of |data|. | 71 | 73 | v8::MaybeLocal<v8::Object> New(Environment* env, | 72 | 74 | char* data, | 73 | 75 | size_t length, | 74 | 76 | FreeCallback callback, | 75 | 77 | void* hint); | | 78 | +// Takes ownership of |data|. Must allocate |data| with malloc() or realloc() | | 79 | +// because ArrayBufferAllocator::Free() deallocates it again with free(). | | 80 | +// Mixing operator new and free() is undefined behavior so don't do that. | 76 | 81 | v8::MaybeLocal<v8::Object> Use(Environment* env, char* data, size_t length); | 77 | 82 | #endif // defined(NODE_WANT_INTERNALS) | 78 | 83 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_crypto.cc +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4479,7 +4479,7 @@ void ECDH::ComputeSecret(const FunctionCallbackInfo<Value>& args) { | 4479 | 4479 | return env->ThrowError("Failed to compute ECDH key"); | 4480 | 4480 | } | 4481 | 4481 |
| 4482 | | - Local<Object> buf = Buffer::New(env, out, out_len).ToLocalChecked(); | | 4482 | + Local<Object> buf = Buffer::Use(env, out, out_len).ToLocalChecked(); | 4483 | 4483 | args.GetReturnValue().Set(buf); | 4484 | 4484 | } | 4485 | 4485 |
| @@ -4544,7 +4544,7 @@ void ECDH::GetPrivateKey(const FunctionCallbackInfo<Value>& args) { | 4544 | 4544 | } | 4545 | 4545 |
| 4546 | 4546 | Local<Object> buf = | 4547 | | - Buffer::New(env, reinterpret_cast<char*>(out), size).ToLocalChecked(); | | 4547 | + Buffer::Use(env, reinterpret_cast<char*>(out), size).ToLocalChecked(); | 4548 | 4548 | args.GetReturnValue().Set(buf); | 4549 | 4549 | } | 4550 | 4550 |
| @@ -4947,7 +4947,7 @@ void RandomBytesCheck(RandomBytesRequest* req, Local<Value> argv[2]) { | 4947 | 4947 | size_t size; | 4948 | 4948 | req->return_memory(&data, &size); | 4949 | 4949 | argv[0] = Null(req->env()->isolate()); | 4950 | | - argv[1] = Buffer::New(req->env(), data, size).ToLocalChecked(); | | 4950 | + argv[1] = Buffer::Use(req->env(), data, size).ToLocalChecked(); | 4951 | 4951 | } | 4952 | 4952 | } | 4953 | 4953 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/stream_wrap.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -223,7 +223,7 @@ void StreamWrap::OnReadImpl(ssize_t nread, | 223 | 223 | CHECK_EQ(pending, UV_UNKNOWN_HANDLE); | 224 | 224 | } | 225 | 225 |
| 226 | | - Local<Object> obj = Buffer::New(env, base, nread).ToLocalChecked(); | | 226 | + Local<Object> obj = Buffer::Use(env, base, nread).ToLocalChecked(); | 227 | 227 | wrap->EmitData(nread, obj, pending_obj); | 228 | 228 | } | 229 | 229 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/udp_wrap.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -408,7 +408,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle, | 408 | 408 | } | 409 | 409 |
| 410 | 410 | char* base = static_cast<char*>(realloc(buf->base, nread)); | 411 | | - argv[2] = Buffer::New(env, base, nread).ToLocalChecked(); | | 411 | + argv[2] = Buffer::Use(env, base, nread).ToLocalChecked(); | 412 | 412 | argv[3] = AddressToJS(env, addr); | 413 | 413 | wrap->MakeCallback(env->onmessage_string(), ARRAY_SIZE(argv), argv); | 414 | 414 | } | |
|