Memory leak fix [Thanks @paul678]