[5/21] gdiplus: fix memory leak in GdipCreateMetafileFromWMF

Evan Stade estade at gmail.com
Tue Jul 31 21:15:12 CDT 2007


Hi,

changelog:
* rearrange error handling
* release the stream
* free the buffer

 dlls/gdiplus/graphics.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

-- 
Evan Stade
-------------- next part --------------
diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c
index 80684ff..52d6c5f 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -846,11 +846,12 @@ GpStatus WINGDIPAPI GdipCreateMetafileFr
     GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
 {
     static int calls;
-    IStream *stream;
+    IStream *stream = NULL;
     UINT read;
     BYTE* copy;
     METAFILEPICT mfp;
     HENHMETAFILE hemf;
+    GpStatus retval = GenericError;
 
     if(!hwmf || !metafile || !placeable)
         return InvalidParameter;
@@ -882,16 +883,19 @@ GpStatus WINGDIPAPI GdipCreateMetafileFr
 
     if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){
         ERR("could not make stream\n");
-        return GenericError;
+        goto end;
     }
 
     *metafile = GdipAlloc(sizeof(GpMetafile));
-    if(!*metafile)  return OutOfMemory;
+    if(!*metafile){
+        retval = OutOfMemory;
+        goto end;
+    }
 
     if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
         (LPVOID*) &((*metafile)->image.picture)) != S_OK){
         GdipFree(*metafile);
-        return GenericError;
+        goto end;
     }
 
     (*metafile)->image.type = ImageTypeMetafile;
@@ -903,11 +907,15 @@ GpStatus WINGDIPAPI GdipCreateMetafileFr
                    - placeable->BoundingBox.Top)) / ((REAL) placeable->Inch);
     (*metafile)->unit = UnitInch;
 
-
     if(delete)
         DeleteMetaFile(hwmf);
 
-    return Ok;
+    retval = Ok;
+
+end:
+    IStream_Release(stream);
+    GdipFree(copy);
+    return retval;
 }
 
 GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
-- 
1.4.1


More information about the wine-patches mailing list