Ensure JS-owned memory is not leaked if a script task fails. Fixes #2201...

....