summaryrefslogtreecommitdiff
path: root/src/udp_wrap.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/udp_wrap.cc')
-rw-r--r--src/udp_wrap.cc14
1 files changed, 2 insertions, 12 deletions
diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc
index f191b3a755..7fba279fca 100644
--- a/src/udp_wrap.cc
+++ b/src/udp_wrap.cc
@@ -275,13 +275,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
SendWrap* req_wrap = new SendWrap(env, req_wrap_obj, have_callback);
size_t msg_size = 0;
- // allocate uv_buf_t of the correct size
- // if bigger than 16 elements
- uv_buf_t bufs_[16];
- uv_buf_t* bufs = bufs_;
-
- if (arraysize(bufs_) < count)
- bufs = new uv_buf_t[count];
+ MaybeStackBuffer<uv_buf_t, 16> bufs(count);
// construct uv_buf_t array
for (size_t i = 0; i < count; i++) {
@@ -313,16 +307,12 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
if (err == 0) {
err = uv_udp_send(&req_wrap->req_,
&wrap->handle_,
- bufs,
+ *bufs,
count,
reinterpret_cast<const sockaddr*>(&addr),
OnSend);
}
- // Deallocate space
- if (bufs != bufs_)
- delete[] bufs;
-
req_wrap->Dispatched();
if (err)
delete req_wrap;