Added SafeHandles, see here: http://blogs.msdn.com/b/bclteam/archive/2005/03/15/396335.aspx to some of the Greenshot code. Not all possible handles have been converted, this should be done to prevent more possible memory/resource leaks.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2427 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2013-01-13 15:53:35 +00:00
commit 502abed36a
5 changed files with 87 additions and 42 deletions

View file

@ -56,18 +56,16 @@ namespace Greenshot.Controls {
/// <param name="hotspotY">Hotspot Y coordinate</param>
/// <returns>Cursor</returns>
private static Cursor CreateCursor(Bitmap bitmap, int hotspotX, int hotspotY) {
IntPtr iconHandle = bitmap.GetHicon();
IntPtr icon;
IconInfo iconInfo = new IconInfo();
User32.GetIconInfo(iconHandle, out iconInfo);
iconInfo.xHotspot = hotspotX;
iconInfo.yHotspot = hotspotY;
iconInfo.fIcon = false;
icon = User32.CreateIconIndirect(ref iconInfo);
Cursor returnCursor = new Cursor(icon);
//User32.DestroyIcon(icon);
User32.DestroyIcon(iconHandle);
return returnCursor;
using (SafeIconHandle iconHandle = new SafeIconHandle( bitmap.GetHicon())) {
IntPtr icon;
IconInfo iconInfo = new IconInfo();
User32.GetIconInfo(iconHandle, out iconInfo);
iconInfo.xHotspot = hotspotX;
iconInfo.yHotspot = hotspotY;
iconInfo.fIcon = false;
icon = User32.CreateIconIndirect(ref iconInfo);
return new Cursor(icon);
}
}
/// <summary>