From 5f14ee617b2c1b05391dfe2c6deecfb4bbcd2928 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Thu, 17 Oct 2013 12:59:05 -0700 Subject: [PATCH] Check for allocation failure in domstring_to_jsval --- src/components/script/dom/bindings/utils.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index c43f510b620..d5ae6319c91 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -218,7 +218,13 @@ pub unsafe fn domstring_to_jsval(cx: *JSContext, string: &DOMString) -> JSVal { match string { &None => JSVAL_NULL, &Some(ref s) => do s.to_utf16().as_imm_buf |buf, len| { - RUST_STRING_TO_JSVAL(JS_NewUCStringCopyN(cx, buf, len as libc::size_t)) + let jsstr = JS_NewUCStringCopyN(cx, buf, len as libc::size_t); + if jsstr.is_null() { + // FIXME: is there something else we should do on failure? + JSVAL_NULL + } else { + RUST_STRING_TO_JSVAL(jsstr) + } } } }