Fix possible issue with double free