GetDocumentation fixes

Medland, Bill Bill.Medland at accpac.com
Tue Jan 8 16:29:21 CST 2002


 <<diff41.txt>> 
-------------- next part --------------
Bill Medland (medbi01 at accpac.com)
Fixed GetDocumentation a little.  When called from RegisterTypeLib it was
leaving the Doc entry uninitialised, leading to page fault when measuring it.
Also ensure correct freeing of resources on failure.

I am not sure how correct the solution is; it works for my case though.

Index: wine/dlls/oleaut32/typelib.c
===================================================================
RCS file: /home/wine/wine/dlls/oleaut32/typelib.c,v
retrieving revision 1.57
diff -u -r1.57 typelib.c
--- wine/dlls/oleaut32/typelib.c	2001/11/19 02:30:03	1.57
+++ wine/dlls/oleaut32/typelib.c	2002/01/08 20:46:47
@@ -3186,6 +3186,8 @@
  * and path, and the context identifier for the library Help topic in the Help
  * file.
  *
+ * On a successful return all non-null BSTR pointers will have been set,
+ * possibly to NULL.
  */
 static HRESULT WINAPI ITypeLib2_fnGetDocumentation(
     ITypeLib2 *iface,
@@ -3209,32 +3211,36 @@
    
     if(index<0)
     { 
-       /* documentation for the typelib */
-       if(pBstrName && This->Name)
-       {
-           *pBstrName = SysAllocString(This->Name);
-
-           if (!(*pBstrName)) return STG_E_INSUFFICIENTMEMORY;
-       }
-       if(pBstrDocString && This->DocString)
-       {
-           *pBstrDocString = SysAllocString(This->DocString);
-
-           if (!(*pBstrDocString)) return STG_E_INSUFFICIENTMEMORY;
-       }
-    
-       if(pdwHelpContext)
-       {
+        /* documentation for the typelib */
+        if(pBstrName)
+        {
+            if (This->Name)
+                if(!(*pBstrName = SysAllocString(This->Name))) goto memerr1;else;
+            else
+                *pBstrName = NULL;
+        }
+        if(pBstrDocString)
+        {
+            if (This->DocString)
+                if(!(*pBstrDocString = SysAllocString(This->DocString))) goto memerr2;else;
+            else if (This->Name)
+                if(!(*pBstrDocString = SysAllocString(This->Name))) goto memerr2;else;
+            else
+                *pBstrDocString = NULL;
+        }
+        if(pdwHelpContext)
+        {
             *pdwHelpContext = This->dwHelpContext;
-       }
-       if(pBstrHelpFile && This->HelpFile)
-       {
-            *pBstrHelpFile = SysAllocString(This->HelpFile);
-
-            if (!(*pBstrHelpFile)) return STG_E_INSUFFICIENTMEMORY;
-       }
+        }
+        if(pBstrHelpFile)
+        {
+            if (This->HelpFile)
+                if(!(*pBstrHelpFile = SysAllocString(This->HelpFile))) goto memerr3;else;
+            else
+                *pBstrHelpFile = NULL;
+        }
 
-       result = S_OK;
+        result = S_OK;
     }
     else 
     {
@@ -3253,6 +3259,12 @@
         }
     }
     return result;
+memerr3:
+    if (pBstrDocString) SysFreeString (*pBstrDocString);
+memerr2:
+    if (pBstrName) SysFreeString (*pBstrName);
+memerr1:
+    return STG_E_INSUFFICIENTMEMORY;
 }
 
 /* ITypeLib::IsName


More information about the wine-patches mailing list