Bug 1018544 - Backport patch from bug 990290 to 1.3T to fix leaks. r=bz. a=1.3t