From cb8d8497c911ecdc7ed1343f9af4dda5dc0c5469 Mon Sep 17 00:00:00 2001 From: RKrom Date: Wed, 25 Aug 2010 10:40:28 +0000 Subject: [PATCH] Made replacing the image more secure, the old code MIGHT have resulted in the Bug #3052665 git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@868 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- GreenshotEditor/Drawing/Surface.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/GreenshotEditor/Drawing/Surface.cs b/GreenshotEditor/Drawing/Surface.cs index 76976675a..0a1647fcd 100644 --- a/GreenshotEditor/Drawing/Surface.cs +++ b/GreenshotEditor/Drawing/Surface.cs @@ -104,14 +104,21 @@ namespace Greenshot.Drawing { } private void SetImage(Image image) { - if (originalImage != null) { - originalImage.Dispose(); - } - if (Image != null) { - Image.Dispose(); - } + // Store old value + Image tmpOriginal = originalImage; + Image tmpImage = Image; + + // Set new values originalImage = new Bitmap(image); Image = new Bitmap(image); + + // Dispose them + if (tmpOriginal != null) { + tmpOriginal.Dispose(); + } + if (tmpImage != null) { + tmpImage.Dispose(); + } } public Surface(Image image) : this() {