Fixes memory double-free bug