Storing rosbag::Bag in std::vector results in segfault

asked 2019-03-28 10:08:58 -0500

luca_giurato gravatar image

I am attempting to store some rosbag::Bags in a std::vector, but calling:

std::vector<rosbag::Bag> bags;
bags.push_back(rosbag::Bag());

results in the following segfault:

#0  0x00007ffff62c7c6d in rosbag::ChunkedFile::swap(rosbag::ChunkedFile&) () from /opt/ros/melodic/lib/librosbag_storage.so
#1  0x00007ffff62a7014 in rosbag::Bag::swap(rosbag::Bag&) () from /opt/ros/melodic/lib/librosbag_storage.so
#2  0x00007ffff62aef75 in rosbag::Bag::Bag(rosbag::Bag&&) () from /opt/ros/melodic/lib/librosbag_storage.so
#3  0x00007ffff7bc0991 in __gnu_cxx::new_allocator<rosbag::Bag>::construct<rosbag::Bag, rosbag::Bag> (this=0x677608, __p=0x687820, __args=...)
    at /usr/bin/../lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/ext/new_allocator.h:136
#4  0x00007ffff7bc05cd in std::allocator_traits<std::allocator<rosbag::Bag> >::construct<rosbag::Bag, rosbag::Bag> (__a=..., __p=0x687820, __args=...)
    at /usr/bin/../lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/alloc_traits.h:475
#5  0x00007ffff7bc06a5 in std::vector<rosbag::Bag, std::allocator<rosbag::Bag> >::_M_realloc_insert<rosbag::Bag> (this=0x677608, __position=non-dereferenceable iterator for std::vector, __args=...)
    at /usr/bin/../lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/vector.tcc:415
#6  0x00007ffff7bc0581 in std::vector<rosbag::Bag, std::allocator<rosbag::Bag> >::emplace_back<rosbag::Bag> (this=0x677608, __args=...)
    at /usr/bin/../lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/vector.tcc:105
#7  0x00007ffff7bbcd40 in std::vector<rosbag::Bag, std::allocator<rosbag::Bag> >::push_back (this=0x677608, __x=...)
    at /usr/bin/../lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/stl_vector.h:954

I have tried to use std::move in the push_back from a Bag object allocated on the stack, but the result is the same (segfault).

How can I correctly create a std::vector of Bag objects?

I am using ROS Melodic on Ubuntu 18.04 on an x86-64 CPU

edit retag flag offensive close merge delete