ole32: Allocate a small temp variable on the stack instead of the heap.

Michael Stefaniuc mstefani at redhat.de
Tue Sep 28 15:43:50 CDT 2010


---
Smatch complained about a redundant NULL check of pfe before the
HeapFree(). But there's a more important problem: the conditions to
alloc and free pfe do not match which would free the pFormatEtc argument
if renderopt != OLERENDER_DRAW. As sizeof(FORMATETC) is only 20 bytes
the short lived pfe variable can be allocated on the stack to simplify
the code.



 dlls/ole32/ole2.c |   22 ++++++++++------------
 1 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/dlls/ole32/ole2.c b/dlls/ole32/ole2.c
index 2b301e4..0829ca1 100644
--- a/dlls/ole32/ole2.c
+++ b/dlls/ole32/ole2.c
@@ -2530,19 +2530,17 @@ HRESULT WINAPI OleCreate(
             if (SUCCEEDED(hres2))
             {
                 DWORD dwConnection;
-                FORMATETC *pfe;
                 if (renderopt == OLERENDER_DRAW && !pFormatEtc) {
-                    pfe = HeapAlloc(GetProcessHeap(), 0, sizeof(FORMATETC));
-                    pfe->cfFormat = 0;
-                    pfe->ptd = NULL;
-                    pfe->dwAspect = DVASPECT_CONTENT;
-                    pfe->lindex = -1;
-                    pfe->tymed = TYMED_NULL;
-                }else
-                    pfe = pFormatEtc;
-                hres = IOleCache_Cache(pOleCache, pfe, ADVF_PRIMEFIRST, &dwConnection);
-                if (!pFormatEtc && pfe)
-                    HeapFree(GetProcessHeap(), 0, pfe);
+                    FORMATETC pfe;
+                    pfe.cfFormat = 0;
+                    pfe.ptd = NULL;
+                    pfe.dwAspect = DVASPECT_CONTENT;
+                    pfe.lindex = -1;
+                    pfe.tymed = TYMED_NULL;
+                    hres = IOleCache_Cache(pOleCache, &pfe, ADVF_PRIMEFIRST, &dwConnection);
+                }
+                else
+                    hres = IOleCache_Cache(pOleCache, pFormatEtc, ADVF_PRIMEFIRST, &dwConnection);
                 IOleCache_Release(pOleCache);
             }
         }
-- 
1.7.2.3



More information about the wine-patches mailing list