boostorg / interprocess

Boost.org interprocess module
http://boost.org/libs/interprocess
132 stars 117 forks source link

Fix iterator invalidation bug. #224

Closed adalisk-emikhaylov closed 1 month ago

adalisk-emikhaylov commented 1 month ago

This fixes https://github.com/boostorg/interprocess/issues/192 and https://github.com/boostorg/interprocess/issues/210 (which seem to describe the same bug).

Here's the code I'm testing this on. I'm using VS 2022 (though some coworkers with the same compiler can't reproduce, I'm not entirely sure why)

#define BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION 1 // This is important, doesn't crash otherwise.

#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/managed_windows_shared_memory.hpp>
#include <boost/interprocess/smart_ptr/unique_ptr.hpp>
#include <iostream>

int main()
{
    std::cout << "Before\n";
    {
        namespace bip = boost::interprocess;
        // Destructor of `x` crashes.
        auto x = bip::managed_windows_shared_memory( bip::open_or_create, "blah", bip::mapped_region::get_page_size() );
    }
    std::cout << "After\n";
}
adalisk-emikhaylov commented 1 month ago

@igaztanaga A friendly ping.

igaztanaga commented 1 month ago

Many thanks for the pull request!