Use auto_ptr to make allocations exception safe