title: why itr = vector.erase(itr) in a loop causing memory curruption? Am I doing something wrong here?
body: <p>Following piece of code is dumping a core sporadically while calling vector.erase(itr). Could you pls point out if I'm doing something wrong here?        </p>
  
  <pre><code>    std::vector&lt;Ntfy&gt;::iterator itr = NtfyVector.begin();
      for ( ; itr != NtfyVector.end(); )
      {
              if (certaion condition) {
                      itr = NtfyVector.erase(itr);
                      continue;
              } else {
                      itr++;
              }
      }
  </code></pre>
  
  <p>Following are the GDB Traces:</p>
  
  <p>(gdb) where</p>
  
  <blockquote>
    <p>#0  0x000000000048cea5 in __gnu_cxx::new_allocator::destroy (this=0x7f0890, __p=0x7adbbf0) at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h:107</p>
    
    <p>#1  0x000000000048da34 in std::vector >::erase (this=0x7f0890, __position={_M_current = 0x7adbc40})
        at /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:115</p>
  </blockquote>
  
  <p>I m using g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3).</p>
  
  <h2>Here is the complete code:</h2>
  
  <p>void NtfyHandle (void)
  {</p>
  
  <pre><code>std::vector&lt;Ntfy&gt;::iterator itr = NtfyVector.begin();
  for ( ; itr != NtfyVector.end(); )
  {
      PF_BOOL bRetry = PF_FALSE;
      switch (itr-&gt;GetOperation()) {
          case PF_SERVICE_ADD:
              {
                  bRetry = LISwithState(itr-&gt;GetServiceName(), itr-&gt;GetNewState(), itr-&gt;GetInvokeId());
              }
              break;
          case PF_SERVICE_REM:
              {
                  liPsPlatform-&gt;SendInvokeResponse(itr-&gt;GetInvokeId(), PF_STATUS_SUCCESS);
              }
              break;
          default: break;
      }
      if (PF_FALSE == bRetry) {
          // Delete the notification from the vector since retry isn't required
          itr = NtfyVector.erase(itr);
          continue;
      } else {
          itr++;
      }
  }
  </code></pre>
  
  <p>}</p>