From 5ce50ece16e52dad94834f977313f36f83732273 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Tue, 19 Nov 2013 11:38:48 +0400 Subject: [PATCH] dgram: fix abort when getting `fd` of closed dgram v8's `messages.js` file's `CallSiteGetMethodName` is running through all object properties and getter to figure out method name of function that appears in stack trace. This run-through will also read `fd` property of `UDPWrap` instance's javascript object, making `UNWRAP()` fail. As a simple alternative to the test case above, one could just keep reference to the dgram handle and try accessing `handle.fd` after it has been fully closed. fix #6536 --- src/udp_wrap.cc | 2 +- test/simple/test-dgram-close.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 73b722f..b33f4e8 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -144,7 +144,7 @@ Handle UDPWrap::GetFD(Local, const AccessorInfo& args) { return v8::Null(); #else HandleScope scope; - UNWRAP(UDPWrap) + UNWRAP_NO_ABORT(UDPWrap) int fd = (wrap == NULL) ? -1 : wrap->handle_.io_watcher.fd; return scope.Close(Integer::New(fd)); #endif diff --git a/test/simple/test-dgram-close.js b/test/simple/test-dgram-close.js index 90ba05a..77af6f1 100644 --- a/test/simple/test-dgram-close.js +++ b/test/simple/test-dgram-close.js @@ -30,5 +30,14 @@ var buf = new Buffer(1024); buf.fill(42); var socket = dgram.createSocket('udp4'); +var handle = socket._handle; socket.send(buf, 0, buf.length, common.PORT, 'localhost'); socket.close(); +socket = null; + +// Verify that accessing handle after closure doesn't throw +setImmediate(function() { + setImmediate(function() { + console.log('Handle fd is: ', handle.fd); + }); +}); -- 2.7.4