Simplify memory ownership with std::unique_ptr.