Segmentation Fault 11 after Main returns
<p>I have a pretty long program with multiple classes so I wont post it unless you need it. But after main returns I get a segmentation fault. </p>

<p>Using GDB I can see this error:</p>

<pre><code>program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000002300103be8
0x00000001000035cc in std::_Rb_tree&lt;std::string, std::string, std::_Identity, std::less,     std::allocator &gt;::_S_right (__x=0x2300103bd0) at stl_tree.h:512
512       { return static_cast&lt;_Link_type&gt;(__x-&gt;_M_right); }
</code></pre>

<p>I'm very new to C++ so this just looks like gibberish to me. Can anyone decipher it? It looks like one of my STL containers might be causing the issue? Any advice on how to fix it?</p>

<p><strong>EDIT With Code:</strong></p>

<p>Okay so I've isolated it down to somewhere in this if block of <code>main</code>, It was the last thing I wrote and when I comment it out the program runs fine.</p>

<pre><code>else if(line.substr(0, 3) == "Rec") // Recieve 
  {       
      istringstream ss(line);
      string s; // output string
      string upc;
      string name;
      int amount;
      int count = 0;
      while(ss &gt;&gt; s) // go through the words in the line
      {
          count++;
          if(count == 2)
            upc = s;
          else if (count == 3)
          {
            istringstream isa(line.substr(20, 2));
            isa &gt;&gt; amount; //Parse the amount
          }
          else if (count == 4)
            name = s;
      }


      warehouses.find(name)-&gt;second.receive_food(upc, amount); //add the food to the warehouse

  }
</code></pre>

<p>To clarify the <code>line</code> we are looking at is in this format:</p>

<pre><code>Receive: 0984523912 7 Tacoma
</code></pre>

<p><code>warehouses</code> is a map : <code>map&lt;string, a4::warehouse&gt; warehouses; //all the warehouses.</code></p>

<p><strong>Here is the warehouse receive method</strong></p>

<pre><code>void warehouse::receive_food(std::string upc, int amount)
{
    items.find(upc)-&gt;second.receive(amount);

    todays_transactions = todays_transactions + amount;
}
</code></pre>

<p>Where <code>items</code> is <code>std::map&lt;std::string, food&gt; items;</code></p>

<p><strong>And Finally the Food Receive method</strong></p>

<pre><code>void food::receive(int amount)
{
    crates.push_back(crate(life, amount));
}
</code></pre>

<p>Where <code>crates</code> is <code>std::list&lt;crate&gt; crates;</code></p>

<p>And a <code>crate</code> is </p>

<pre><code>    class crate
{
    public:
        crate(int, int);
        ~crate();
        int life;
        int quantity;
};
</code></pre>
