fix free_mem issues