Fixes bug 983807 use a try/finally r=peterbe