Converting a bitmap to a region – memory leak fix

There is a memory leak in the code, posted under the article : “Converting a bitmap to a region”.

At the end of the BitmapToRegion function, the lines:

	// Clean up				
	SelectObject(hDC, holdBmp);
	DeleteDC(hDC);

must be changed into :

	// Clean u
	GlobalFree(hData);
	SelectObject(hDC, holdBmp);
	DeleteDC(hDC);

Download source – 178KB

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read