Fix crash in access to freed memory