From: Rose Hellsing <rose@pinkro.se> GdipCreateMetafileFromWmf converts the WMF to EMF for playback but the caller may still expect the original HMETAFILE to follow the documented ownership rules (kept on failure, released by gdiplus on success when delete=TRUE). Track the source handle on the GpMetafile and release it from METAFILE_Free, leaving the failure path to the caller per MSDN. --- dlls/gdiplus/gdiplus_private.h | 2 ++ dlls/gdiplus/metafile.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h index cc5f823214b..a1ed2cf7dbf 100644 --- a/dlls/gdiplus/gdiplus_private.h +++ b/dlls/gdiplus/gdiplus_private.h @@ -479,7 +479,9 @@ struct GpMetafile{ GpUnit unit; MetafileType metafile_type; HENHMETAFILE hemf; + HMETAFILE hwmf; int preserve_hemf; /* if true, hemf belongs to the app and should not be deleted */ + int preserve_hwmf; /* if true, hwmf belongs to the app and should not be deleted */ /* recording */ HDC record_dc; diff --git a/dlls/gdiplus/metafile.c b/dlls/gdiplus/metafile.c index 20adc83b95f..83484b9a00e 100644 --- a/dlls/gdiplus/metafile.c +++ b/dlls/gdiplus/metafile.c @@ -692,6 +692,8 @@ void METAFILE_Free(GpMetafile *metafile) DeleteEnhMetaFile(CloseEnhMetaFile(metafile->record_dc)); if (!metafile->preserve_hemf) DeleteEnhMetaFile(metafile->hemf); + if (!metafile->preserve_hwmf) + DeleteMetaFile(metafile->hwmf); if (metafile->record_graphics) { WARN("metafile closed while recording\n"); @@ -4315,6 +4317,9 @@ GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete, if (retval == Ok) { + (*metafile)->hwmf = hwmf; + (*metafile)->preserve_hwmf = !delete; + if (placeable) { (*metafile)->image.xres = (REAL)placeable->Inch; @@ -4330,11 +4335,12 @@ GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete, else (*metafile)->metafile_type = MetafileTypeWmf; (*metafile)->image.format = ImageFormatWMF; - - if (delete) DeleteMetaFile(hwmf); } else + { DeleteEnhMetaFile(hemf); + } + return retval; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11180