From 84efb8602fb995507ce80166d71493c76ae7ff65 Mon Sep 17 00:00:00 2001 From: Makoto Kato Date: Wed, 14 Oct 2009 12:57:42 +0900 Subject: [PATCH] Bug 521937 - Crash using js-ctypes open method with a wrong path [@PR_UnloadLibrary | mozilla::ctypes::Library::Finalize]. r=dwitte --- js/ctypes/Library.cpp | 12 ++++++++---- js/ctypes/tests/unit/test_jsctypes.js.in | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/js/ctypes/Library.cpp b/js/ctypes/Library.cpp index ba17c66877b..091d23b48d2 100644 --- a/js/ctypes/Library.cpp +++ b/js/ctypes/Library.cpp @@ -73,6 +73,14 @@ Library::Create(JSContext* cx, jsval aPath) if (!libraryObj) return NULL; + // initialize the library + if (!JS_SetReservedSlot(cx, libraryObj, 0, PRIVATE_TO_JSVAL(NULL))) + return NULL; + + // initialize our Function list to empty + if (!JS_SetReservedSlot(cx, libraryObj, 1, PRIVATE_TO_JSVAL(NULL))) + return NULL; + // attach API functions if (!JS_DefineFunctions(cx, libraryObj, sLibraryFunctions)) return NULL; @@ -117,10 +125,6 @@ Library::Create(JSContext* cx, jsval aPath) if (!JS_SetReservedSlot(cx, libraryObj, 0, PRIVATE_TO_JSVAL(library))) return NULL; - // initialize our Function list to empty - if (!JS_SetReservedSlot(cx, libraryObj, 1, PRIVATE_TO_JSVAL(NULL))) - return NULL; - return libraryObj; } diff --git a/js/ctypes/tests/unit/test_jsctypes.js.in b/js/ctypes/tests/unit/test_jsctypes.js.in index a563a608107..a4dca89e974 100644 --- a/js/ctypes/tests/unit/test_jsctypes.js.in +++ b/js/ctypes/tests/unit/test_jsctypes.js.in @@ -109,6 +109,9 @@ function run_test() obj.t = test_i8; do_check_eq(test_i8(), 123); do_check_eq(obj.t(), 123); + + // bug 521937 + do_check_throws(function () { var nolib = ctypes.open("notfoundlibrary.dll"); nolib.close(); }, Error); } function run_void_tests(library) {