From a00ccb0fb9eb716925058b0a20fcec9251de3309 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Thu, 1 Sep 2016 18:14:02 -0400 Subject: 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 Reviewed-By: Anna Henningsen --- src/udp_wrap.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/udp_wrap.cc') 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(malloc(suggested_size)); + buf->base = static_cast(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(realloc(buf->base, nread)); + char* base = static_cast(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); -- cgit v1.2.1