title: Program crashes when trying to access the inner map
body: <p>Following is a small reader writer program. The writer writes values to a map of maps, the write is successful.
   There is another process called reader which reads the contents of the SHM, the reader has no problem in reading the key of the outer map, however if we try to access the contents of the inner map it crashes. 
    I have checked the container size and it prints 2 for case1 which is fine as the inner map contains 2 elements for the key "case1".</p>
  
  <p>However, when I try to access to inner map the program crashes, is the way I am accessing the inner map not correct. Following are the code snippets that I am using.</p>
  
  <h3>ShmTypedefs.h</h3>
  
  <pre><code>#ifndef __SHM_TYPE_DEFS__
      #define __SHM_TYPE_DEFS__
      #include &lt;boost/interprocess/allocators/allocator.hpp&gt;
      #include &lt;boost/interprocess/managed_shared_memory.hpp&gt;
      #include &lt;boost/interprocess/containers/string.hpp&gt;
      #include &lt;boost/interprocess/containers/map.hpp&gt;
  
      //the strings also need to be assigned from the shared memory
      typedef boost::interprocess::allocator&lt;void, boost::interprocess::managed_shared_memory::segment_manager&gt; VoidAllocator;
      typedef boost::interprocess::allocator&lt;char, boost::interprocess::managed_shared_memory::segment_manager&gt; CharAllocator;
      typedef boost::interprocess::basic_string&lt;char, std::char_traits&lt;char&gt;, CharAllocator&gt; SharedString;
  
      //Note that map&lt;Key, MappedType&gt;'s value_type is std::pair&lt;const Key, MappedType&gt;,
      //so the allocator must allocate that pair.
      typedef SharedString KeyType;
      typedef boost::interprocess::map&lt;SharedString, int&gt;  MappedType;
      typedef std::pair&lt;const KeyType, MappedType&gt; ValueType;
  
      //allocator for the string
      typedef boost::interprocess::allocator&lt;SharedString, boost::interprocess::managed_shared_memory::segment_manager&gt; StringAllocator;
      //allocator of for the map.
      typedef boost::interprocess::allocator&lt;ValueType, boost::interprocess::managed_shared_memory::segment_manager&gt; ShmemAllocator;
      typedef boost::interprocess::allocator&lt;ValueType, boost::interprocess::managed_shared_memory::segment_manager&gt; ShmemAllocator;
      //third parameter argument is the ordering function is used to compare the keys.
      typedef boost::interprocess::map&lt;KeyType, MappedType, std::less&lt;KeyType&gt;, ShmemAllocator&gt; MySHMMap;
  #endif
  </code></pre>
  
  <h3>writer.cxx</h3>
  
  <pre><code>    #include &lt;boost/interprocess/containers/map.hpp&gt;
      #include &lt;functional&gt;
      #include &lt;utility&gt;
      #include &lt;ShmTypedefs.h&gt;
      #include &lt;iostream&gt;
      using namespace boost::interprocess;
  
      int main ()
      {
        // remove earlier existing SHM
        shared_memory_object::remove("SharedMemoryName");
  
        // create new
        managed_shared_memory segment(create_only,"SharedMemoryName",65536);
  
        //Initialize the shared memory STL-compatible allocator
        ShmemAllocator alloc_inst (segment.get_segment_manager());
  
        //third parameter argument is the ordering function is used to compare the keys.
        typedef map&lt;KeyType, MappedType, std::less&lt;KeyType&gt;, ShmemAllocator&gt; MySHMMap;
  
        //offset ptr within SHM for map
        //After construction m_pmap will contain the only object that has been consturcted in pmap[0]
        //If we construct another object it will goto pmap[1]
  
        offset_ptr&lt;MySHMMap&gt; m_pmap = segment.construct&lt;MySHMMap&gt;("MySHMMapName")(std::less&lt;SharedString&gt;(), alloc_inst);
  
        //Insert data in the map
        StringAllocator string_alloc_instance( segment.get_segment_manager() );
  
        SharedString key("case1", string_alloc_instance );
        SharedString inner_map_key("inner_case1", string_alloc_instance );
  
        SharedString key1("case2", string_alloc_instance );
        SharedString inner_map_key1("inner_case2", string_alloc_instance );
  
        SharedString inner_map_key2("inner_case3", string_alloc_instance );
  
        m_pmap[0][key][inner_map_key] = 2030;
        m_pmap[0][key1][inner_map_key1] = 2031;
        m_pmap[0][key][inner_map_key2] = 2034;
        std::cout&lt;&lt;"\n "&lt;&lt;m_pmap[0][key][inner_map_key]&lt;&lt; std::endl;
        std::cout&lt;&lt;"\n "&lt;&lt;m_pmap[0][key1][inner_map_key1]&lt;&lt; std::endl;
        return 0;
      }
  </code></pre>
  
  <p>reader.cxx</p>
  
  <pre><code> #include &lt;boost/interprocess/containers/map.hpp&gt;
  #include &lt;functional&gt;
  #include &lt;utility&gt;
  #include &lt;iostream&gt;
  #include &lt;ShmTypedefs.h&gt;
  
  using namespace boost::interprocess;
  
  int main ()
  {
  
    try
    {
  
      managed_shared_memory segment(open_or_create, "SharedMemoryName",65536);
  
      int size= segment.find&lt;MySHMMap&gt;("MySHMMapName").second;
      std::cout&lt;&lt; "size of map " &lt;&lt; size &lt;&lt; std::endl;
      offset_ptr&lt;MySHMMap&gt; m_pmap = segment.find&lt;MySHMMap&gt;("MySHMMapName").first;
      MySHMMap :: iterator iter = m_pmap[0].begin();
      MySHMMap :: iterator iter_end = m_pmap[0].end();
      for(; iter != iter_end; ++iter ) {
        std::cout&lt;&lt;"\n "&lt;&lt; iter-&gt;first&lt;&lt;std::endl;
        if( iter-&gt;first == "case1" ) {
           MappedType::iterator iti = (iter-&gt;second).begin();
  
           MappedType::iterator iti_end = (iter-&gt;second).end();
           for( ;iti != iti_end; ++iti ) {
           std::cout &lt;&lt; "symbol " &lt;&lt; iti-&gt;first &lt;&lt; " time " &lt;&lt; iti-&gt;second &lt;&lt; std::endl;
            }
        }
      }
    }
    catch(std::exception &amp;e) {
      std::cout&lt;&lt;" error  " &lt;&lt; e.what() &lt;&lt;std::endl;
      shared_memory_object::remove("SharedMemoryName");
    }
    return 0;
  }
  </code></pre>
  
  <p>Stack Trace:</p>
  
  <p>Output when I run the program =></p>
  
  <pre><code>   droy@apdeva01 shmmapofmap&gt; ./bin/reader
      size of map 1
      case1
      Matched case 1
      Size of the inner container is 2 units
      Segmentation fault (core dumped)
  </code></pre>
  
  <p>Core output:</p>
  
  <pre><code>(gdb) bt
  #0  get_right () at /home/dev/build/third_party/64-rhel5/boost_1_47_0/include/boost/intrusive/detail/rbtree_node.hpp:130
  #1  next_node () at /home/dev/build/third_party/64-rhel5/boost_1_47_0/include/boost/intrusive/detail/tree_algorithms.hpp:441
  #2  next_node () at /home/dev/build/third_party/64-rhel5/boost_1_47_0/include/boost/intrusive/rbtree_algorithms.hpp:353
  #3  operator++ () at /home/dev/build/third_party/64-rhel5/boost_1_47_0/include/boost/intrusive/detail/tree_node.hpp:119
  #4  prot_incr ()
      at /home/dev/build/third_party/64-rhel5/boost_1_47_0/include/boost/interprocess/containers/container/detail/tree.hpp:326
  #5  operator++ ()
      at /home/dev/build/third_party/64-rhel5/boost_1_47_0/include/boost/interprocess/containers/container/detail/tree.hpp:395
  #6  __distance&lt;boost::container::containers_detail::rbtree&lt;boost::container::basic_string&lt;char, std::char_traits&lt;char&gt;, boost::interprocess::allocator&lt;char, boost::interprocess::segment_manager&lt;char, boost::interprocess::rbtree_best_fit&lt;boost::interprocess::mutex_family, boost::interprocess::offset_ptr&lt;void&gt;, 0ul&gt;, boost::interprocess::iset_index&gt; &gt; &gt;, std::pair&lt;boost::container::basic_string&lt;char, std::char_traits&lt;char&gt;, boost::interprocess::allocator&lt;char, boost::interprocess::segment_manager&lt;char, boost::interprocess::rbtree_best_fit&lt;boost::interprocess::mutex_family, boost::interprocess::offset_ptr&lt;void&gt;, 0ul&gt;, boost::interprocess::iset_index&gt; &gt; &gt; const, int&gt;, boost::container::containers_detail::select1st&lt;std::pair&lt;boost::container::basic_string&lt;char, std::char_traits&lt;char&gt;, boost::interprocess::allocator&lt;char, boost::interprocess::segment_manager&lt;char, boost::interprocess::rbtree_best_fit&lt;boost::interprocess::mutex_family, boost::interprocess::offset_ptr&lt;void&gt;, 0ul&gt;, boost::interprocess::iset_index&gt; &gt; &gt; const, int&gt; &gt;, std::less&lt;boost::container::basic_string&lt;char, std::char_traits&lt;char&gt;, boost::interprocess::allocator&lt;char, boost::interprocess::segment_manager&lt;char, boost::interprocess::rbtree_best_fit&lt;boost::interprocess::mutex_family, boost::interprocess::offset_ptr&lt;void&gt;, 0ul&gt;, boost::interprocess::iset_index&gt; &gt; &gt; &gt;, std::allocator&lt;std::pair&lt;boost::container::basic_string&lt;char, std::char_traits&lt;char&gt;, boost::interprocess::allocator&lt;char, boost::interprocess::segment_manager&lt;char, boost::interprocess::rbtree_best_fit&lt;boost::interprocess::mutex_family, boost::interprocess::offset_ptr&lt;void&gt;, 0ul&gt;, boost::interprocess::iset_index&gt; &gt; &gt; const, int&gt; &gt; &gt;::iterator&gt; ()
      at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_iterator_base_funcs.h:79
  #7  distance&lt;boost::container::containers_detail::rbtree&lt;boost::container::basic_string&lt;char, std::char_traits&lt;char&gt;, boost::interprocess::allocator&lt;char, boost::interprocess::segment_manager&lt;char, boost::interprocess::rbtree_best_fit&lt;boost::interproce---Type &lt;return&gt; to continue, or q &lt;return&gt; to quit---
  ss::mutex_family, boost::interprocess::offset_ptr&lt;void&gt;, 0ul&gt;, boost::interprocess::iset_index&gt; &gt; &gt;, std::pair&lt;boost::container::basic_string&lt;char, std::char_traits&lt;char&gt;, boost::interprocess::allocator&lt;char, boost::interprocess::segment_manager&lt;char, boost::interprocess::rbtree_best_fit&lt;boost::interprocess::mutex_family, boost::interprocess::offset_ptr&lt;void&gt;, 0ul&gt;, boost::interprocess::iset_index&gt; &gt; &gt; const, int&gt;, boost::container::containers_detail::select1st&lt;std::pair&lt;boost::container::basic_string&lt;char, std::char_traits&lt;char&gt;, boost::interprocess::allocator&lt;char, boost::interprocess::segment_manager&lt;char, boost::interprocess::rbtree_best_fit&lt;boost::interprocess::mutex_family, boost::interprocess::offset_ptr&lt;void&gt;, 0ul&gt;, boost::interprocess::iset_index&gt; &gt; &gt; const, int&gt; &gt;, std::less&lt;boost::container::basic_string&lt;char, std::char_traits&lt;char&gt;, boost::interprocess::allocator&lt;char, boost::interprocess::segment_manager&lt;char, boost::interprocess::rbtree_best_fit&lt;boost::interprocess::mutex_family, boost::interprocess::offset_ptr&lt;void&gt;, 0ul&gt;, boost::interprocess::iset_index&gt; &gt; &gt; &gt;, std::allocator&lt;std::pair&lt;boost::container::basic_string&lt;char, std::char_traits&lt;char&gt;, boost::interprocess::allocator&lt;char, boost::interprocess::segment_manager&lt;char, boost::interprocess::rbtree_best_fit&lt;boost::interprocess::mutex_family, boost::interprocess::offset_ptr&lt;void&gt;, 0ul&gt;, boost::interprocess::iset_index&gt; &gt; &gt; const, int&gt; &gt; &gt;::iterator&gt; ()
      at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_iterator_base_funcs.h:114
  #8  main () at /home/user/droy/src/quotes/debshmutils/shmmapofmap/src/reader.cxx:33
  </code></pre>