[pywin32-checkins] pywin32/Pythonwin win32bitmap.cpp,1.1,1.2
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2005-06-26 12:59:43
|
Update of /cvsroot/pywin32/pywin32/Pythonwin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9022 Modified Files: win32bitmap.cpp Log Message: Fix [ 1208530 ] PyBitmap.GetBitmapBits Memory Leak Index: win32bitmap.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/Pythonwin/win32bitmap.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** win32bitmap.cpp 1 Sep 1999 23:33:00 -0000 1.1 --- win32bitmap.cpp 26 Jun 2005 12:59:33 -0000 1.2 *************** *** 467,489 **** BITMAP bm; if (pBitmap->GetObject(sizeof(bm), &bm)==0) ! RETURN_ERR("GetObject failed on bitmap"); ! UINT cnt = bm.bmHeight*bm.bmWidthBytes*bm.bmPlanes; ! HGLOBAL hMem = GlobalAlloc(GHND, cnt); ! if (!hMem) { ! RETURN_ERR("GlobalAlloc failed on bitmap"); ! } ! LPBYTE lpbDst=(LPBYTE)GlobalLock(hMem); HBITMAP handle = (HBITMAP)pBitmap->GetSafeHandle(); ! DWORD bytes = GetBitmapBits(handle, cnt, (LPVOID)lpbDst); ! if (bytes != (DWORD)cnt) { ! GlobalUnlock(hMem); ! RETURN_ERR("GetBitmapBits failed on bitmap"); ! } PyObject* rc = PyTuple_New(cnt); for (UINT i = 0; i < cnt; i++) { ! PyTuple_SetItem(rc, i, Py_BuildValue("i", (int)lpbDst[i])); } ! GlobalUnlock(hMem); ! return rc; } --- 467,487 ---- BITMAP bm; if (pBitmap->GetObject(sizeof(bm), &bm)==0) ! RETURN_ERR("GetObject failed on bitmap"); ! UINT cnt = bm.bmHeight*bm.bmWidthBytes*bm.bmPlanes; ! char *bits = (char *)malloc(cnt); ! if (!bits) ! return PyErr_NoMemory(); HBITMAP handle = (HBITMAP)pBitmap->GetSafeHandle(); ! DWORD bytes = GetBitmapBits(handle, cnt, (void *)bits); ! if (bytes != (DWORD)cnt) { ! free(bits); ! RETURN_ERR("GetBitmapBits failed on bitmap"); ! } PyObject* rc = PyTuple_New(cnt); for (UINT i = 0; i < cnt; i++) { ! PyTuple_SetItem(rc, i, Py_BuildValue("i", (int)bits[i])); } ! free(bits); ! return rc; } |