   Help! Memory leak problem
  Hello,I have no clue where these memory leaks are that are being reported by Rational Purify.Im thinking it''s in my SurfaceManager class, so Im going to paste the code here.If anyone knows what''s causing them, tell me please . If it''s not here, then I need to look over the rest of my code and find out whats up Starting Purify''d app.exe at 08/03/2003 19:54:16    [W] MLK: Memory leak of 16384 bytes from 1 block allocated in VirtualAlloc [KERNEL32.dll]CSurfaceManager.cppCSurfaceManager::CSurfaceManager(void){}CSurfaceManager::~CSurfaceManager(void){SLit iter = SurfaceList.begin();while( iter != SurfaceList.end() ){(*iter)->Release();*iter = NULL;iter++;}}void CSurfaceManager::LoadImageToSurface(IDirectDrawSurface7 *destination, char *filename, int width, int height){DWORD nBytes;HGLOBAL hMem = NULL;LPVOID lpData = NULL;IStream *pstm = NULL;IPicture *pic = NULL;HBITMAP hBmp = NULL;HDC hdcImage;HDC hdc;BITMAP   bm;HANDLE hFile = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);if (hFile != INVALID_HANDLE_VALUE) {nBytes = GetFileSize(hFile, NULL);if ((hMem = GlobalAlloc(GMEM_MOVEABLE, nBytes)) != NULL) {if ((lpData = GlobalLock(hMem)) != NULL) {ReadFile(hFile, lpData, nBytes, &nBytes, NULL);GlobalUnlock(hMem);}}CloseHandle(hFile);}if (lpData && nBytes) {HRESULT oleret = CreateStreamOnHGlobal(hMem, TRUE, &pstm);if (SUCCEEDED(oleret) && pstm) {oleret = OleLoadPicture(pstm, nBytes, FALSE, IID_IPicture, (void **)&pic);pstm->Release();if (FAILED(oleret)) pic = NULL;}}   if(hmem)  GlobalFree(hMem);if (pic) { HWND hWndDesk = GetDesktopWindow();HDC hdcDesk = GetWindowDC(hWndDesk);OLE_XSIZE_HIMETRIC picX;OLE_YSIZE_HIMETRIC picY;pic->get_Width(&picX);pic->get_Height(&picY);RECT rt = {100, 0};rt.right = MulDiv(GetDeviceCaps(hdcDesk, LOGPIXELSX), picX, 2540);rt.bottom = MulDiv(GetDeviceCaps(hdcDesk, LOGPIXELSY), picY, 2540);HDC hdcMem = CreateCompatibleDC(hdcDesk);hBmp = CreateCompatibleBitmap(hdcDesk, rt.right, rt.bottom);ReleaseDC(hWndDesk, hdcDesk);HBITMAP oldBmp = (HBITMAP)SelectObject(hdcMem, hBmp);pic->Render(hdcMem, 0, 0, rt.right, rt.bottom, 0, picY, picX, -picY, &rt);pic->Release();hBmp = (HBITMAP)SelectObject(hdcMem, oldBmp);DeleteDC(hdcMem);}destination->Restore();hdcImage = CreateCompatibleDC(NULL);SelectObject(hdcImage, hBmp);GetObject(hBmp, sizeof(bm), &bm);width = width == 0 ? bm.bmWidth  : width;height = height == 0 ? bm.bmHeight : height;destination->GetDC(&hdc);BitBlt(hdc, 0, 0, width, height, hdcImage, 0, 0, SRCCOPY);destination->ReleaseDC(hdc);DeleteDC(hdcImage);}void CSurfaceManager::CreateSurface(IDirectDrawSurface7 **lpSource, int width, int height){DDSURFACEDESC2 ddsd;ZeroMemory(&ddsd, sizeof(ddsd));ddsd.dwSize = sizeof(ddsd);ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;ddsd.dwWidth = width;ddsd.dwHeight = height;ddrawobj->CreateSurface(&ddsd, lpSource, NULL);SurfaceList.push_front(*lpSource);}  CSurfaceManager.h#include <ddraw.h>#include <list>#include <ocidl.h>#include <olectl.h>typedef std::list SurfaceList;typedef SurfaceList::iterator SLit;class CSurfaceManager{public:CSurfaceManager(void);~CSurfaceManager(void);inline void SetObject(IDirectDraw7 *object) { ddrawobj = object; }inline SurfaceList& GetList() { return SurfaceList;}void LoadImageToSurface(IDirectDrawSurface7 *destination, char *filename, int width, int height);void CreateSurface(IDirectDrawSurface7 **lpSource, int width, int height);private:IDirectDraw7 *ddrawobj;SurfaceList SurfaceList;};  
  HBITMAP oldBmp = (HBITMAP)SelectObject(hdcMem, hBmp);Remeber to release that one too . ;  I did a DeleteObject on it and still got the memory leak errors.Maybe this section of code isn''t the problem ;  A few posts down, you will find a post entitled ''Tracking Down Memory Leaks''clicky Michael BartmanCEO, Lead ProgrammerDark Omen Studios