Fix heap bug