title: Memory Leak while using CvSeq in cvFindContours
body: <p>I am new to OpenCV and i faced some problem while using it.</p>
  
  <p>Currently i am work on Binary Partitioning Tree (BPT) algorithm. Basically I need split the image into many regions, and based on some parameter. 2 regions will merged and form 1 new region, which consists of these 2 regions.</p>
  
  <p>I managed to get initial regions by using cvWatershed. I also created a vector to store these regions, each in 1 vector block. However, I get memory leak when I tried to move the contour information into vector. It says, memory leak.</p>
  
  <pre><code>for (int h = 0; h &lt;compCount; h++)  // compCount - Amount of regions found through cvWaterShed
  {
      cvZero(WSRegion);               // clears out an image, used for painting 
      Region.push_back(EmptyNode);    // create an empty vector slot
      CvScalar RegionColor = colorTab[h]; // the color of the region in watershed
  
      for (int i = 0; i &lt;WSOut-&gt;height; i++)
      {
          for (int j = 0; j &lt;WSOut-&gt;width; j++)
          {
              CvScalar s = cvGet2D(WSOut, i, j);  // get pixel color in watershed image
              if (s.val[0] == RegionColor.val[0] &amp;&amp; s.val[1] == RegionColor.val[1] &amp;&amp; s.val[2] == RegionColor.val[2])
              {
                  cvSet2D(WSRegion, i, j, cvScalarAll(255));  // paint the pixel to white if it has the same color with the region[h]
  
              }
          }
      }
  
      MemStorage = cvCreateMemStorage();   // create memory storage
      cvFindContours(WSRegion, MemStorage, &amp;contours, sizeof(CvContour), CV_RETR_LIST);
      Region[h].RegionContour = cvCloneSeq(contours);  // clone and store in vector Region[h]
      Region[h].RegionContour-&gt;h_next = NULL;
  }
  </code></pre>
  
  <p>Is it any ways I can solve this problem? Or is there any alternative that I do not need to create a new memory storage for every region vector？ Thank You in advance</p>