id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 3950,boost::interprocess::mapped_region destructor deletes shm where it shouldn't.,Lénaïc Huard ,Ion Gaztañaga,"Hello, I have troubles with the following piece of code: {{{ #include #include #include int main() { boost::interprocess::mapped_region aRegion( boost::interprocess::anonymous_shared_memory( sizeof( int ) ) ); *(int *)aRegion.get_address() = 0x33; return EXIT_SUCCESS; } }}} It should create an anonymous memory region and writes an int in it. Whereas this piece of code works when compiled with gcc without optimizations, when it is compiled with -O2 or -O3 with gcc 4.4.3, it produces a segmentation fault. strace and gdb show that the shared memory is mmapped and unmapped before the assignment is done. (Whereas when the code is compiled without optimization, the shared memory is clearly mapped, then the assignement is done, then it is unmapped.) My understanding of what happens is that: - the anonymous_shared_memory() function calls raw_mapped_region_creator::create_posix_mapped_region which creates a local mapped_region object. - This mapped_region object is non-copyable, but movable. When the return statement for that local object is called, it invokes mapped_region::mapped_region(BOOST_INTERPROCESS_RV_REF(mapped_region) other) which: - create the returned object as invalid, - swap the content of the local object with the one of the ""invalid initialized"" returned object. Thanks to this, the returned object has the proper values and the local object is set as ""invalid"" just before its destructor is called so that the shm won't be unmapped at raw_mapped_region_creator::create_posix_mapped_region and anonymous_shared_memory exit. For a reason I don't understand, I have the feeling that, when the code is compiled with gcc 4.4.3 -O2 or -O3, this ""swap with invalid mapped_region"" mechanism is zapped out so that the shm mmapped at the beginning of anonymous_shared_memory is unmapped by ~mapped_region when this function returns.",Bugs,closed,Boost 1.45.0,interprocess,Boost 1.42.0,Problem,fixed,,