GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: plug memory leaks · tcper/node@6457746

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_buffer.h
    • node_crypto.cc
    • stream_wrap.cc
    • udp_wrap.cc
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_buffer.h‎

Copy file name to clipboardExpand all lines: src/node_buffer.h
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,17 @@ static inline bool IsWithinBounds(size_t off, size_t len, size_t max) {
6767
// in src/node_internals.h because of a circular dependency.
6868
#if defined(NODE_WANT_INTERNALS)
6969
v8::MaybeLocal<v8::Object> New(Environment* env, size_t size);
70+
// Makes a copy of |data|.
7071
v8::MaybeLocal<v8::Object> New(Environment* env, const char* data, size_t len);
72+
// Takes ownership of |data|.
7173
v8::MaybeLocal<v8::Object> New(Environment* env,
7274
char* data,
7375
size_t length,
7476
FreeCallback callback,
7577
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.
7681
v8::MaybeLocal<v8::Object> Use(Environment* env, char* data, size_t length);
7782
#endif // defined(NODE_WANT_INTERNALS)
7883

Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4479,7 +4479,7 @@ void ECDH::ComputeSecret(const FunctionCallbackInfo<Value>& args) {
44794479
return env->ThrowError("Failed to compute ECDH key");
44804480
}
44814481

4482-
Local<Object> buf = Buffer::New(env, out, out_len).ToLocalChecked();
4482+
Local<Object> buf = Buffer::Use(env, out, out_len).ToLocalChecked();
44834483
args.GetReturnValue().Set(buf);
44844484
}
44854485

@@ -4544,7 +4544,7 @@ void ECDH::GetPrivateKey(const FunctionCallbackInfo<Value>& args) {
45444544
}
45454545

45464546
Local<Object> buf =
4547-
Buffer::New(env, reinterpret_cast<char*>(out), size).ToLocalChecked();
4547+
Buffer::Use(env, reinterpret_cast<char*>(out), size).ToLocalChecked();
45484548
args.GetReturnValue().Set(buf);
45494549
}
45504550

@@ -4947,7 +4947,7 @@ void RandomBytesCheck(RandomBytesRequest* req, Local<Value> argv[2]) {
49474947
size_t size;
49484948
req->return_memory(&data, &size);
49494949
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();
49514951
}
49524952
}
49534953

Collapse file

‎src/stream_wrap.cc‎

Copy file name to clipboardExpand all lines: src/stream_wrap.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ void StreamWrap::OnReadImpl(ssize_t nread,
223223
CHECK_EQ(pending, UV_UNKNOWN_HANDLE);
224224
}
225225

226-
Local<Object> obj = Buffer::New(env, base, nread).ToLocalChecked();
226+
Local<Object> obj = Buffer::Use(env, base, nread).ToLocalChecked();
227227
wrap->EmitData(nread, obj, pending_obj);
228228
}
229229

Collapse file

‎src/udp_wrap.cc‎

Copy file name to clipboardExpand all lines: src/udp_wrap.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
408408
}
409409

410410
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();
412412
argv[3] = AddressToJS(env, addr);
413413
wrap->MakeCallback(env->onmessage_string(), ARRAY_SIZE(argv), argv);
414414
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.