[oleaut32] Removes extra string allocation for varformat:VarMonthName

Benjamin Arai me at benjaminarai.com
Thu Aug 3 21:59:22 CDT 2006


Hi,

Updates GetLocaleInfoW by directly allocating into the destination
string instead of allocating into temp buffer first.

 Changelog:
  - Removes temporary allocation string
 ---
  dlls/oleaut32/varformat.c |   13 ++++---------
  1 files changed, 4 insertions(+), 9 deletions(-)

-- 
Benjamin Arai
http://www.benjaminarai.com
-------------- next part --------------

diff --git a/dlls/oleaut32/varformat.c b/dlls/oleaut32/varformat.c
index 8dfc7fc..4a579b4 100644
--- a/dlls/oleaut32/varformat.c
+++ b/dlls/oleaut32/varformat.c
@@ -2531,7 +2531,6 @@ HRESULT WINAPI VarMonthName(INT iMonth, 
 {
   DWORD localeValue;
   INT size;
-  WCHAR *str;
 
   if ((iMonth < 1)  || (iMonth > 12))
     return E_INVALIDARG;
@@ -2549,18 +2548,14 @@ HRESULT WINAPI VarMonthName(INT iMonth, 
     ERR("GetLocaleInfo 0x%lx failed.\n", localeValue);
     return HRESULT_FROM_WIN32(GetLastError());
   }
-  str = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*size);
-  if (!str)
+  *pbstrOut = SysAllocStringLen(NULL,sizeof(WCHAR)*size);
+  if (!*pbstrOut)
     return E_OUTOFMEMORY;
-  size = GetLocaleInfoW(LOCALE_USER_DEFAULT,localeValue, str, size);
+  size = GetLocaleInfoW(LOCALE_USER_DEFAULT,localeValue, *pbstrOut+1, size);
   if (!size) {
     ERR("GetLocaleInfo of 0x%lx failed in 2nd stage?!\n", localeValue);
-    HeapFree(GetProcessHeap(),0,str);
+    SysFreeString(*pbstrOut);
     return HRESULT_FROM_WIN32(GetLastError());
   }
-  *pbstrOut = SysAllocString(str);
-  HeapFree(GetProcessHeap(),0,str);
-  if (!*pbstrOut)
-    return E_OUTOFMEMORY;
   return S_OK;
 }
-- 
1.4.0


More information about the wine-patches mailing list