title: Crash when using delete [] to delete a pointer
body: <p>The code I'm using to make output of pTemp:</p>
  
  <pre><code>if (m_pTImgFrame != NULL)
  {
      for (int i = 0; i &lt; m_nFrameNumber; i++)
      {
          TImage* pTemp = (TImage*)m_pTImgFrame[i];
          if (pTemp != NULL)
          {
              TCHAR buffer[256] = { 0 };
              _stprintf_s(buffer, 256, _T("%d,%d,%d,%d,%d,%d,%d,%d\n"), 
                  pTemp-&gt;attrib,
                  pTemp-&gt;h,
                  pTemp-&gt;pitch,
                  pTemp-&gt;w,
                  pTemp-&gt;data[0],
                  pTemp-&gt;data[1], 
                  pTemp-&gt;data[2], 
                  pTemp-&gt;data[3]);
              OutputDebugString(buffer);
  
              delete[] pTemp;
              m_pTImgFrame[i] = NULL;
          }
      }
      delete []m_pTImgFrame;
      m_pTImgFrame = NULL;
  }
  </code></pre>
  
  <p>The <strong>origin</strong> code which still <strong>crashes</strong></p>
  
  <pre><code>if (m_pTImgFrame != NULL)
  {
      for (int i = 0; i &lt; m_nFrameNumber; i++)
      {
          BYTE* pTemp = (BYTE*)m_pTImgFrame[i];
          if (pTemp != NULL)
          {
              delete[] pTemp;
              m_pTImgFrame[i] = NULL;
          }
      }
      delete []m_pTImgFrame;
      m_pTImgFrame = NULL;
  }
  </code></pre>
  
  <p>declaration of variables:</p>
  
  <pre><code>typedef unsigned int        UINT;
  typedef struct _TImage
  {
      int  w;         
      int  h;         
      int  pitch;     
      int  attrib;    
      unsigned char data[4];  
  } TImage;
  
  UINT        m_nFrameNumber;     
  UINT*       m_pnFrameDelay;     
  TImage**    m_pTImgFrame;
  
  PBITMAPINFOHEADER pbih; 
  typedef struct tagBITMAPINFOHEADER{
      DWORD      biSize;
      LONG       biWidth;
      LONG       biHeight;
      WORD       biPlanes;
      WORD       biBitCount;
      DWORD      biCompression;
      DWORD      biSizeImage;
      LONG       biXPelsPerMeter;
      LONG       biYPelsPerMeter;
      DWORD      biClrUsed;
      DWORD      biClrImportant;
  } BITMAPINFOHEADER, FAR *LPBITMAPINFOHEADER, *PBITMAPINFOHEADER;
  </code></pre>
  
  <p>Allocation:</p>
  
  <pre><code>    m_pTImgFrame = new TImage*[1];
      m_pTImgFrame[0] = (TImage*)new BYTE[sizeof(TImage) - 4 + 4 * width * pbih-&gt;biHeight];
      m_pTImgFrame[0]-&gt;attrib = imageAttrib8888;
      m_pTImgFrame[0]-&gt;w = width;
      m_pTImgFrame[0]-&gt;h = pbih-&gt;biHeight;
      m_pTImgFrame[0]-&gt;pitch = 4 * width;
      LOG(_T("32width=%d, height=%d"), width, pbih-&gt;biHeight);
      for(j=pbih-&gt;biHeight-1; j&gt;=0; j--)
      {
          int indexDst = (pbih-&gt;biHeight-j-1) * width * 4;
          //int indexSrc = j * pbih-&gt;biWidth * 4;
          int indexSrc = j * ((pbmi-&gt;bmiHeader.biWidth * cClrBits +31) &amp; ~31) /8/*bmpInfo.bmWidthBytes*/;
          for(i=0; i&lt; width; i++)
          {
              m_pTImgFrame[0]-&gt;data[indexDst++] = lpBits[indexSrc++];
              m_pTImgFrame[0]-&gt;data[indexDst++] = lpBits[indexSrc++];
              m_pTImgFrame[0]-&gt;data[indexDst++] = lpBits[indexSrc++];
              m_pTImgFrame[0]-&gt;data[indexDst++] = 255;
              indexSrc++;
          }
      }
  </code></pre>
  
  <p>The code will crash when run the line
  <code>delete [] pTemp</code> if the m_nFrameNumber is 1 (I only saw the crash happened when it is 1 but I'm not sure);The output of each value of the pTemp is correct, so why it crashes ?</p>