gdiplus: Store the image type on a Graphics object in case the image is freed.

Vincent Povirk madewokherd at gmail.com
Sat Mar 2 14:38:15 CST 2013


For bug 14873.

It's OK to access metafiles in GdipDeleteGraphics because the act of
destroying a metafile will remove the Graphics object's reference to
it.
-------------- next part --------------
From 6f568432468250dcafa33145e76a87bbee7bbf3f Mon Sep 17 00:00:00 2001
From: Vincent Povirk <vincent at codeweavers.com>
Date: Sat, 2 Mar 2013 14:28:01 -0600
Subject: [PATCH] gdiplus: Store the image type on a Graphics object in case
 the image is freed.

---
 dlls/gdiplus/gdiplus_private.h |    1 +
 dlls/gdiplus/graphics.c        |    5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h
index cb7330e..87f3b8b 100644
--- a/dlls/gdiplus/gdiplus_private.h
+++ b/dlls/gdiplus/gdiplus_private.h
@@ -154,6 +154,7 @@ struct GpGraphics{
     BOOL owndc;
     BOOL alpha_hdc;
     GpImage *image;
+    ImageType image_type;
     SmoothingMode smoothing;
     CompositingQuality compqual;
     InterpolationMode interpolation;
diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c
index 853027c..1150675 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -2195,6 +2195,9 @@ GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics)
     (*graphics)->hwnd = NULL;
     (*graphics)->owndc = FALSE;
     (*graphics)->image = image;
+    /* We have to store the image type here because the image may be freed
+     * before GdipDeleteGraphics is called, and metafiles need special treatment. */
+    (*graphics)->image_type = image->type;
     (*graphics)->smoothing = SmoothingModeDefault;
     (*graphics)->compqual = CompositingQualityDefault;
     (*graphics)->interpolation = InterpolationModeBilinear;
@@ -2389,7 +2392,7 @@ GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
     if(!graphics) return InvalidParameter;
     if(graphics->busy) return ObjectBusy;
 
-    if (graphics->image && graphics->image->type == ImageTypeMetafile)
+    if (graphics->image && graphics->image_type == ImageTypeMetafile)
     {
         stat = METAFILE_GraphicsDeleted((GpMetafile*)graphics->image);
         if (stat != Ok)
-- 
1.7.10.4


More information about the wine-patches mailing list