diff options
author | Michael Dawson <michael_dawson@ca.ibm.com> | 2016-09-01 18:14:02 -0400 |
---|---|---|
committer | Michael Dawson <michael_dawson@ca.ibm.com> | 2016-09-06 09:39:06 -0400 |
commit | a00ccb0fb9eb716925058b0a20fcec9251de3309 (patch) | |
tree | 91c1aa556e0519d73c4b04238a5cf02f67342886 /src/udp_wrap.cc | |
parent | a290ddfdc9cd9453886d433060c5132095d916c4 (diff) | |
download | node-new-a00ccb0fb9eb716925058b0a20fcec9251de3309.tar.gz |
src: normalize malloc, realloc
malloc(0) and realloc(ptr, 0) have implementation-defined behavior in
that the standard allows them to either return a unique pointer or a
nullptr for zero-sized allocation requests. Normalize by always using
a nullptr.
- Introduce node::malloc, node::realloc and node::calloc that should
be used throught our source.
- Update all existing node source files to use the new functions
instead of the native allocation functions.
Fixes: https://github.com/nodejs/node/issues/7549
PR-URL: https://github.com/nodejs/node/pull/7564
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/udp_wrap.cc')
-rw-r--r-- | src/udp_wrap.cc | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 1cf9678cb1..f191b3a755 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -384,7 +384,7 @@ void UDPWrap::OnSend(uv_udp_send_t* req, int status) { void UDPWrap::OnAlloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { - buf->base = static_cast<char*>(malloc(suggested_size)); + buf->base = static_cast<char*>(node::Malloc(suggested_size)); buf->len = suggested_size; if (buf->base == nullptr && suggested_size > 0) { @@ -426,7 +426,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle, return; } - char* base = static_cast<char*>(realloc(buf->base, nread)); + char* base = static_cast<char*>(node::Realloc(buf->base, nread)); argv[2] = Buffer::New(env, base, nread).ToLocalChecked(); argv[3] = AddressToJS(env, addr); wrap->MakeCallback(env->onmessage_string(), arraysize(argv), argv); |