Fix memory leak if an exception is thrown within a rejected promise

This commit is contained in:
Gordon Williams 2018-05-09 11:52:31 +01:00
parent 94d5063aa9
commit 61585f7069
4 changed files with 17 additions and 3 deletions

View File

@ -5,6 +5,8 @@
Pixl.js: Reorder pins so 0..13 are also D0..13 for better Arduino compatibility
Fix dump() when used with code written using E.setBootCode(..), (fix #1398)
Allow parseInt/parseFloat to be used on very large strings if the number doesn't extend right to the end (fix #1397)
nRF5x: Fix memory leak on NRF.connect
Fix memory leak if an exception is thrown within a rejected promise
1v97 : nRF52: fix NRF.on('connect',...) issue
STM32: Fix setDeviceClockCmd error for USB.setConsole()

View File

@ -73,7 +73,7 @@ void _jswrap_promise_resolve_or_reject(JsVar *promise, JsVar *data, JsVar *fn) {
JsVar *exception = jspGetException();
if (exception) {
_jswrap_promise_queuereject(chainedPromise, exception);
jsvUnLock2(result, chainedPromise);
jsvUnLock3(exception, result, chainedPromise);
return;
}

12
tests/test_promise10.js Normal file
View File

@ -0,0 +1,12 @@
function test() {
(new Promise(function(resolve,reject){
reject("Oh No!");
})).then(function(x) {
console.log("Ok");
}).catch(function() {
console.log("Fail (expected)");
result=1;
throw "This used to leak memory!";
});
}
test(); // it used to fail here

View File

@ -2,10 +2,10 @@
function test() {
if (busy) return;
(new Promise(function(go){go(1)})).then(function(x) {
console("Ok");
console.log("Ok");
result = x;
}).catch(function() {
console("Fail");
console.log("Fail");
});
}
var busy = true;