[PATCH] riched20: Fix IRichEditOle COM aggregation (Valgrind).

Sven Baars sven.wine at gmail.com
Wed Jan 30 15:03:20 CST 2019


Signed-off-by: Sven Baars <sven.wine at gmail.com>
---
This supersedes 157453. I hope Michael likes it better like this :)

 dlls/riched20/editor.c  | 13 ++++++++-----
 dlls/riched20/editor.h  |  1 -
 dlls/riched20/editstr.h |  2 +-
 dlls/riched20/richole.c |  8 +-------
 dlls/riched20/txtsrv.c  |  5 +----
 5 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 2bb285866b..b7254d2a21 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1124,6 +1124,7 @@ static HRESULT insert_static_object(ME_TextEditor *editor, HENHMETAFILE hemf, HB
   LPOLECLIENTSITE     lpClientSite = NULL;
   LPDATAOBJECT        lpDataObject = NULL;
   LPOLECACHE          lpOleCache = NULL;
+  LPRICHEDITOLE       lpReOle = NULL;
   STGMEDIUM           stgm;
   FORMATETC           fm;
   CLSID               clsid;
@@ -1156,7 +1157,8 @@ static HRESULT insert_static_object(ME_TextEditor *editor, HENHMETAFILE hemf, HB
   }
 
   if (OleCreateDefaultHandler(&CLSID_NULL, NULL, &IID_IOleObject, (void**)&lpObject) == S_OK &&
-      IRichEditOle_GetClientSite(editor->reOle, &lpClientSite) == S_OK &&
+      IUnknown_QueryInterface(editor->reOle, &IID_IRichEditOle, (void**)&lpReOle) == S_OK &&
+      IRichEditOle_GetClientSite(lpReOle, &lpClientSite) == S_OK &&
       IOleObject_SetClientSite(lpObject, lpClientSite) == S_OK &&
       IOleObject_GetUserClassID(lpObject, &clsid) == S_OK &&
       IOleObject_QueryInterface(lpObject, &IID_IOleCache, (void**)&lpOleCache) == S_OK &&
@@ -1188,6 +1190,7 @@ static HRESULT insert_static_object(ME_TextEditor *editor, HENHMETAFILE hemf, HB
   if (lpStorage)      IStorage_Release(lpStorage);
   if (lpDataObject)   IDataObject_Release(lpDataObject);
   if (lpOleCache)     IOleCache_Release(lpOleCache);
+  if (lpReOle)        IRichEditOle_Release(lpReOle);
 
   return hr;
 }
@@ -3215,7 +3218,7 @@ void ME_DestroyEditor(ME_TextEditor *editor)
   ITextHost_Release(editor->texthost);
   if (editor->reOle)
   {
-    IRichEditOle_Release(editor->reOle);
+    IUnknown_Release(editor->reOle);
     editor->reOle = NULL;
   }
   OleUninitialize();
@@ -4820,9 +4823,9 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     if (!editor->reOle)
       if (!CreateIRichEditOle(NULL, editor, (LPVOID *)&editor->reOle))
         return 0;
-    *(LPVOID *)lParam = editor->reOle;
-    IRichEditOle_AddRef(editor->reOle);
-    return 1;
+    if (IUnknown_QueryInterface(editor->reOle, &IID_IRichEditOle, (LPVOID *)lParam) == S_OK)
+      return 1;
+    return 0;
   }
   case EM_GETPASSWORDCHAR:
   {
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 2da7365a6e..2633fa8f1b 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -239,7 +239,6 @@ void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run* run, BOOL selected) DECLSPE
 void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize) DECLSPEC_HIDDEN;
 void ME_CopyReObject(REOBJECT *dst, const REOBJECT *src, DWORD flags) DECLSPEC_HIDDEN;
 void ME_DeleteReObject(struct re_object *re_object) DECLSPEC_HIDDEN;
-void ME_GetITextDocument2OldInterface(IRichEditOle *iface, LPVOID *ppvObj) DECLSPEC_HIDDEN;
 
 /* editor.c */
 ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/editstr.h b/dlls/riched20/editstr.h
index 96c9a1f644..28be524806 100644
--- a/dlls/riched20/editstr.h
+++ b/dlls/riched20/editstr.h
@@ -385,7 +385,7 @@ typedef struct tagME_TextEditor
 {
   HWND hWnd, hwndParent;
   ITextHost *texthost;
-  IRichEditOle *reOle;
+  IUnknown *reOle;
   BOOL bEmulateVersion10;
   ME_TextBuffer *pBuffer;
   ME_Cursor *pCursors;
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index dc1a3b8405..447e7d4599 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -5471,7 +5471,7 @@ LRESULT CreateIRichEditOle(IUnknown *outer_unk, ME_TextEditor *editor, LPVOID *p
         reo->outer_unk = outer_unk;
     else
         reo->outer_unk = &reo->IUnknown_inner;
-    *ppvObj = &reo->IRichEditOle_iface;
+    *ppvObj = &reo->IUnknown_inner;
 
     return 1;
 }
@@ -5691,9 +5691,3 @@ void ME_CopyReObject(REOBJECT *dst, const REOBJECT *src, DWORD flags)
         IOleClientSite_AddRef(dst->polesite);
     }
 }
-
-void ME_GetITextDocument2OldInterface(IRichEditOle *iface, LPVOID *ppvObj)
-{
-    IRichEditOleImpl *This = impl_from_IRichEditOle(iface);
-    *ppvObj = &This->ITextDocument2Old_iface;
-}
diff --git a/dlls/riched20/txtsrv.c b/dlls/riched20/txtsrv.c
index 18c2ca9d69..639a94fbd0 100644
--- a/dlls/riched20/txtsrv.c
+++ b/dlls/riched20/txtsrv.c
@@ -83,10 +83,7 @@ static HRESULT WINAPI ITextServicesImpl_QueryInterface(IUnknown *iface, REFIID r
       if (!This->editor->reOle)
          if (!CreateIRichEditOle(This->outer_unk, This->editor, (void **)(&This->editor->reOle)))
             return E_OUTOFMEMORY;
-      if (IsEqualIID(riid, &IID_ITextDocument) || IsEqualIID(riid, &IID_ITextDocument2Old))
-         ME_GetITextDocument2OldInterface(This->editor->reOle, ppv);
-      else
-         *ppv = This->editor->reOle;
+      return IUnknown_QueryInterface(This->editor->reOle, riid, ppv);
    } else {
       *ppv = NULL;
       FIXME("Unknown interface: %s\n", debugstr_guid(riid));
-- 
2.17.1




More information about the wine-devel mailing list