fix mem leak on maskedCopy