From 97292b87fc6a92f779c365b149a5c2314cc5751f Mon Sep 17 00:00:00 2001 From: Nikhil Marathe Date: Fri, 10 Jan 2014 14:07:46 -0800 Subject: [PATCH] Bug 958684 - Fix AsyncErrorReporter leak in Promises. r=mccr8 --- dom/promise/Promise.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dom/promise/Promise.cpp b/dom/promise/Promise.cpp index 7b2ddb2be277..aa472b8d7a7a 100644 --- a/dom/promise/Promise.cpp +++ b/dom/promise/Promise.cpp @@ -561,12 +561,16 @@ Promise::MaybeReportRejected() } // Now post an event to do the real reporting async - NS_DispatchToMainThread( + // Since Promises preserve their wrapper, it is essential to nsRefPtr<> the + // AsyncErrorReporter, otherwise if the call to DispatchToMainThread fails, it + // will leak. See Bug 958684. + nsRefPtr r = new AsyncErrorReporter(JS_GetObjectRuntime(&mResult.toObject()), report, nullptr, isChromeError, - win)); + win); + NS_DispatchToMainThread(r); } void