I’ve narrowed down in my application that my AVI video player is leaking memory. I have the following code:
...
LPBYTE pChunk = new BYTE[lSize];
if(!pChunk)
return false;
hr = AVIStreamReadFormat(pStream, AVIStreamStart(pStream), pChunk, &lSize);
if(hr)
{
delete [] pChunk;
return false;
}
m_pVideoFormats[i] = (LPBITMAPINFO)pChunk;
Later on when it comes time to remove the video, I simply just delete:
if(m_pVideoFormats[i])
delete [] ((LPBYTE)m_pVideoFormats[i]);
Will this cause a memory leak because of how I’m casting this pointer around? Thanks!
No, that won’t leak. It doesn’t matter how you cast it around, the important thing is that you delete the same type you allocated. You’ve matched
BYTE[]toBYTE[], so that’s not your problem.