Resource leak fix