[PATCH 2/5] setupapi: Avoid unnecessary buffer allocation in SetupDiCreateDeviceInfoA().

Zebediah Figura z.figura12 at gmail.com
Tue Nov 27 19:55:35 CST 2018


Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/setupapi/devinst.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c
index 8ce1344cda..a9145adc44 100644
--- a/dlls/setupapi/devinst.c
+++ b/dlls/setupapi/devinst.c
@@ -1341,8 +1341,8 @@ BOOL WINAPI SetupDiCreateDeviceInfoA(HDEVINFO DeviceInfoSet, const char *name,
         const GUID *ClassGuid, PCSTR DeviceDescription, HWND hwndParent, DWORD CreationFlags,
         PSP_DEVINFO_DATA DeviceInfoData)
 {
+    WCHAR nameW[MAX_DEVICE_ID_LEN];
     BOOL ret = FALSE;
-    LPWSTR DeviceNameW = NULL;
     LPWSTR DeviceDescriptionW = NULL;
 
     if (!name || strlen(name) >= MAX_DEVICE_ID_LEN)
@@ -1351,23 +1351,18 @@ BOOL WINAPI SetupDiCreateDeviceInfoA(HDEVINFO DeviceInfoSet, const char *name,
         return FALSE;
     }
 
-    DeviceNameW = MultiByteToUnicode(name, CP_ACP);
-    if (DeviceNameW == NULL) return FALSE;
+    MultiByteToWideChar(CP_ACP, 0, name, -1, nameW, sizeof(nameW));
 
     if (DeviceDescription)
     {
         DeviceDescriptionW = MultiByteToUnicode(DeviceDescription, CP_ACP);
         if (DeviceDescriptionW == NULL)
-        {
-            MyFree(DeviceNameW);
             return FALSE;
-        }
     }
 
-    ret = SetupDiCreateDeviceInfoW(DeviceInfoSet, DeviceNameW, ClassGuid, DeviceDescriptionW,
+    ret = SetupDiCreateDeviceInfoW(DeviceInfoSet, nameW, ClassGuid, DeviceDescriptionW,
             hwndParent, CreationFlags, DeviceInfoData);
 
-    MyFree(DeviceNameW);
     MyFree(DeviceDescriptionW);
 
     return ret;
-- 
2.14.1




More information about the wine-devel mailing list