title: Segfault when adding an element to a std::map
body: <p>I have something strange happening when I try to insert one element in a map</p>
  
  <p>main.cpp</p>
  
  <pre><code>S3Wrapper wrapper = S3Wrapper::getS3Wrapper();
  int main(){
      return 0;
  }
  </code></pre>
  
  <p>So basically only the singleton is called for S3Wrapper</p>
  
  <p>S3Wrapper.hpp</p>
  
  <pre><code>class S3Wrapper
  {
      S3Wrapper(std::string bucketName);
  public:
      ~S3Wrapper();
      static S3Wrapper   &amp;getS3Wrapper(std::string name = BUCKET_NAME);
  }
  </code></pre>
  
  <p>and S3Wrapper.cpp</p>
  
  <pre><code>static std::map&lt;std::string, S3Wrapper*&gt; _wrapperMap;
  S3Wrapper&amp;  S3Wrapper::getS3Wrapper(std::string name)
  {
      auto it = _wrapperMap.find(name);
      if (it == _wrapperMap.end())
      {
          auto t = new S3Wrapper(name);
          _wrapperMap[name] = t;
          return *(_wrapperMap[name]);
      }
      return *(it-&gt;second);
  }
  </code></pre>
  
  <p>When I compile I don't have any error/warning but then the program segfault:</p>
  
  <pre><code>g++ main.cpp S3Wrapper.cpp -std=c++0x -ls3 -g3
  </code></pre>
  
  <p>result of gdb</p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  0x00007ffff7937c4a in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
  (gdb) bt
  #0  0x00007ffff7937c4a in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
  #1  0x0000000000406295 in std::_Rb_tree_iterator&lt;std::pair&lt;std::string const, S3Wrapper*&gt; &gt;::operator-- (this=0x7fffffffd8b0) at /usr/include/c++/4.8/bits/stl_tree.h:204
  #2  0x00000000004061f7 in std::_Rb_tree&lt;std::string, std::pair&lt;std::string const, S3Wrapper*&gt;, std::_Select1st&lt;std::pair&lt;std::string const, S3Wrapper*&gt; &gt;, std::less&lt;std::string&gt;, std::allocator&lt;std::pair&lt;std::string const, S3Wrapper*&gt; &gt; &gt;::_M_get_insert_unique_pos (this=0x60b580 &lt;_wrapperMap&gt;, __k=...) at /usr/include/c++/4.8/bits/stl_tree.h:1333
  #3  0x00000000004058f5 in std::_Rb_tree&lt;std::string, std::pair&lt;std::string const, S3Wrapper*&gt;, std::_Select1st&lt;std::pair&lt;std::string const, S3Wrapper*&gt; &gt;, std::less&lt;std::string&gt;, std::allocator&lt;std::pair&lt;std::string const, S3Wrapper*&gt; &gt; &gt;::_M_get_insert_hint_unique_pos (this=0x60b580 &lt;_wrapperMap&gt;, __position=..., __k=...) at /usr/include/c++/4.8/bits/stl_tree.h:1425
  #4  0x000000000040511c in std::_Rb_tree&lt;std::string, std::pair&lt;std::string const, S3Wrapper*&gt;, std::_Select1st&lt;std::pair&lt;std::string const, S3Wrapper*&gt; &gt;, std::less&lt;std::string&gt;, std::allocator&lt;std::pair&lt;std::string const, S3Wrapper*&gt; &gt; &gt;::_M_emplace_hint_unique&lt;std::piecewise_construct_t const&amp;, std::tuple&lt;std::string const&amp;&gt;, std::tuple&lt;&gt; &gt;(std::_Rb_tree_const_iterator&lt;std::pair&lt;std::string const, S3Wrapper*&gt; &gt;, std::piecewise_construct_t const&amp;, std::tuple&lt;std::string const&amp;&gt;&amp;&amp;, std::tuple&lt;&gt;&amp;&amp;) (this=0x60b580 &lt;_wrapperMap&gt;, __pos=...) at /usr/include/c++/4.8/bits/stl_tree.h:1673
  #5  0x0000000000404d24 in std::map&lt;std::string, S3Wrapper*, std::less&lt;std::string&gt;, std::allocator&lt;std::pair&lt;std::string const, S3Wrapper*&gt; &gt; &gt;::operator[] (this=0x60b580 &lt;_wrapperMap&gt;, __k=...)
      at /usr/include/c++/4.8/bits/stl_map.h:465
  #6  0x0000000000404945 in S3Wrapper::getS3Wrapper (name=...) at S3Wrapper.cpp:55
  #7  0x00000000004021e3 in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at main.cpp:8
  #8  0x00000000004022ce in _GLOBAL__sub_I_wrapper () at main.cpp:41
  #9  0x0000000000406b7d in __libc_csu_init ()
  #10 0x00007ffff7308e55 in __libc_start_main (main=0x401edc &lt;main()&gt;, argc=1, argv=0x7fffffffdc28, init=0x406b30 &lt;__libc_csu_init&gt;, fini=&lt;optimized out&gt;, rtld_fini=&lt;optimized out&gt;, 
      stack_end=0x7fffffffdc18) at libc-start.c:246
  #11 0x0000000000401b79 in _start ()
  </code></pre>
  
  <p>line55:  <code>_wrapperMap[name] = t;</code></p>
  
  <p>If I insert t in a vector I don't have any problem</p>