From f218d94af4a7f70086c931be01b1bed9c76bfee0 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Thu, 5 Sep 2013 15:50:51 -0700 Subject: [PATCH] handle_wrap: properly don't abort on unwrap From commit 756ae2c all the WRAP/UNWRAP were moved to a single location for ease of use. In a single location NO_ABORT should have been used but wasn't. This caused HandleWrap::Close to abort. Below is the applicable code change as demonstration there was no abort specified when unwrapping the object. void HandleWrap::Close(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); - HandleWrap *wrap = static_cast( - args.This()->GetAlignedPointerFromInternalField(0)); + HandleWrap* wrap; + UNWRAP(args.This(), HandleWrap, wrap); Also included a test that will reproduce the abort. --- src/handle_wrap.cc | 2 +- test/simple/test-handle-wrap-close-abort.js | 36 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/simple/test-handle-wrap-close-abort.js diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 4aba0efc4d9..858b55cdd4e 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -68,7 +68,7 @@ void HandleWrap::Close(const FunctionCallbackInfo& args) { HandleScope scope(node_isolate); HandleWrap* wrap; - NODE_UNWRAP(args.This(), HandleWrap, wrap); + NODE_UNWRAP_NO_ABORT(args.This(), HandleWrap, wrap); // guard against uninitialized handle or double close if (wrap == NULL || wrap->handle__ == NULL) return; diff --git a/test/simple/test-handle-wrap-close-abort.js b/test/simple/test-handle-wrap-close-abort.js new file mode 100644 index 00000000000..287c38b23a9 --- /dev/null +++ b/test/simple/test-handle-wrap-close-abort.js @@ -0,0 +1,36 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var common = require('../common'); + +process.on('uncaughtException', function() { }); + +setTimeout(function() { + process.nextTick(function() { + var c = setInterval(function() { + clearInterval(c); + throw new Error('setInterval'); + }); + }); + setTimeout(function() { + throw new Error('setTimeout'); + }); +});