Fix use of previously freed memory