title: Will clearing an already empty vector lead to undefined behavior?
body: <p>What happens if I <code>clear</code> a <code>vector</code> which was already cleared before? 
  I tried it out in Visual Studio and it did not lead to any run-time errors. But I'm hunting for a possible cause to an exception (below)  And wanted to know if this could be the reason?</p>
  
  <pre><code>*** glibc detected *** process.out: double free or corruption (out): 0x01a0b588 *** 
  </code></pre>
  
  <p>Updating code:</p>
  
  <pre><code>bool myclass::Sort(SortType enSortOption)
  {
  
    bool bRet = TRUE;
  
  
    m_oVecOfIntsOrig.clear();
    m_oVecOfIntsSorted.clear();
  
    for(int i = 0;i&lt;m_oList.listsize();i++)
    {
      m_oVecOfIntsOrig.push_back(i);
    }
    m_oVecOfIntsSorted = m_oVecOfIntsOrig; 
    //Just sort the indices     
    switch(enSortOption)
    {
    case Alpha:
      { 
        t_SortStructAlpha sSortAlpha(this);
        sort( m_oVecOfIntsSorted.begin(), m_oVecOfIntsSorted.end(), sSortAlpha );        
      }
      break;
    case Dist:
      {        
        t_SortStructDist sSortDist(this);
        sort( m_oVecOfIntsSorted.begin(), m_oVecOfIntsSorted.end(), sSortDist );
      }
      break;
    case none:  
      {
  
        //Nothing to do
        return TRUE;
      }
      break;  
    default:
      {
        bRet = FALSE;
  
      }
      break;
    }
  
    //Update the list based on sorted index vector
    ListElem oSortedListElements;
    //this clear function simply clears all the 7 constituent vectors. 
    oSortedListElements.vClear();
    if(TRUE == bGetSortedList(oSortedListElements))
    {
      //If successfully copied to temp object, then update member variable
      //m_oList is what I'm intending to display
      m_oList.vClear();
      m_oList = oSortedListElements;
    }
    else
    {
      //copy failed
      bRet = FALSE;
  
    }
    return bRet;
  }
  
  
  bool myclass::bGetSortedList(ListElem&amp; oSortedListElements)
  {
  
    bool bRet = TRUE;
  
    //Creating object from beginning, so clear old contents if any
    oSortedListElements.vClear();
    /* Sort done. Now update the list based on new indices*/
    for(int u16Index = 0; u16Index&lt;m_oVecOfIntsSorted.size(); u16Index++)
    {
      if(
        (m_oVecOfIntsSorted.at(u16Index) &gt;= m_oListConstituents.oVec1.size())
        ||
        (m_oVecOfIntsSorted.at(u16Index) &gt;= m_oListConstituents.oVec2.size())
        ||
        (m_oVecOfIntsSorted.at(u16Index) &gt;= m_oListConstituents.oVec3.size())
        ||
        (m_oVecOfIntsSorted.at(u16Index) &gt;= m_oListConstituents.oVec4.size())
        ||
        (m_oVecOfIntsSorted.at(u16Index) &gt;= m_oListConstituents.oVec5.size())
        ||
        (m_oVecOfIntsSorted.at(u16Index) &gt;= m_oListConstituents.oVec6.size())
        ||
        (m_oVecOfIntsSorted.at(u16Index) &gt;= m_oListConstituents.oVec7.size())
        )
      {
        //out of bounds check
        return FALSE;
      }
      //m_oListConstituents contains overall list
      oSortedListElements.oVec1.push_back(m_oListConstituents.oVec1.at(m_oVecOfIntsSorted.at(u16Index)));
      oSortedListElements.oVec2.push_back(m_oListConstituents.oVec2.at(m_oVecOfIntsSorted.at(u16Index)));
      oSortedListElements.oVec3.push_back(m_oListConstituents.oVec3.at(m_oVecOfIntsSorted.at(u16Index)));
      oSortedListElements.oVec4.push_back(m_oListConstituents.oVec4.at(m_oVecOfIntsSorted.at(u16Index)));
      oSortedListElements.oVec5.push_back(m_oListConstituents.oVec5.at(m_oVecOfIntsSorted.at(u16Index)));
      oSortedListElements.oVec6.push_back(m_oListConstituents.oVec6.at(m_oVecOfIntsSorted.at(u16Index)));
      oSortedListElements.oVec7.push_back(m_oListConstituents.oVec7.at(m_oVecOfIntsSorted.at(u16Index)));     
  
    }
  
    return bRet;
  
  }
  </code></pre>