title: Does this leak memory? How can I prevent it?
body: <p>I see that this <a href="https://stackoverflow.com/questions/8501753/how-to-display-opencv-mat-on-mfc-view">question</a>'s answer is really popular regarding how to print a cv::Mat image into an MFC application.</p>
  
  <p>However, I was wondering if there is a memory leak there? or if there is none, how is that possible?</p>
  
  <p>In specific, I'm wondering about the <code>memset(bmih, 0, sizeof(*bmih))</code> part. Is it that MFC somehow manages the memory here? Can someone provide some information regarding this?</p>
  
  <pre><code>void COpenCVTestView::FillBitmapInfo(BITMAPINFO* bmi, int width, int height, int bpp, int origin) 
  { 
  assert(bmi &amp;&amp; width &gt;= 0 &amp;&amp; height &gt;= 0 &amp;&amp; (bpp == 8 || bpp == 24 || bpp == 32)); 
  
  BITMAPINFOHEADER* bmih = &amp;(bmi-&gt;bmiHeader); 
  // this part shouldn't leak?
  memset(bmih, 0, sizeof(*bmih)); 
  bmih-&gt;biSize = sizeof(BITMAPINFOHEADER); 
  bmih-&gt;biWidth = width; 
  bmih-&gt;biHeight = origin ? abs(height) : -abs(height); 
  bmih-&gt;biPlanes = 1; 
  bmih-&gt;biBitCount = (unsigned short)bpp; 
  bmih-&gt;biCompression = BI_RGB; 
  
  if (bpp == 8) 
  { 
      RGBQUAD* palette = bmi-&gt;bmiColors; 
  
              for (int i = 0; i &lt; 256; i++) 
      { 
          palette[i].rgbBlue = palette[i].rgbGreen = palette[i].rgbRed = (BYTE)i; 
          palette[i].rgbReserved = 0; 
      } 
  } 
  }
  </code></pre>