Andrew Nguyen : setupapi: Fix some memory leaks in SetupDiGetINFClassA.

Alexandre Julliard julliard at winehq.org
Mon Jan 17 10:59:49 CST 2011


Module: wine
Branch: master
Commit: c66d27c55588b0ab3406ce4729348beec3aab536
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=c66d27c55588b0ab3406ce4729348beec3aab536

Author: Andrew Nguyen <anguyen at codeweavers.com>
Date:   Sat Jan 15 02:28:37 2011 -0600

setupapi: Fix some memory leaks in SetupDiGetINFClassA.

Spotted with Valgrind.

---

 dlls/setupapi/devinst.c |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c
index 1d318fe..5b8fb3c 100644
--- a/dlls/setupapi/devinst.c
+++ b/dlls/setupapi/devinst.c
@@ -3998,10 +3998,26 @@ BOOL WINAPI SetupDiGetINFClassA(PCSTR inf, LPGUID class_guid, PSTR class_name,
     PWSTR class_nameW = NULL;
     UNICODE_STRING infW;
 
-    if (inf) RtlCreateUnicodeStringFromAsciiz(&infW, inf);
-    else infW.Buffer = NULL;
+    if (inf)
+    {
+        if (!RtlCreateUnicodeStringFromAsciiz(&infW, inf))
+        {
+            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+            return FALSE;
+        }
+    }
+    else
+        infW.Buffer = NULL;
+
     if (class_name && size)
-        class_nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
+    {
+        if (!(class_nameW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR))))
+        {
+            RtlFreeUnicodeString(&infW);
+            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+            return FALSE;
+        }
+    }
 
     retval = SetupDiGetINFClassW(infW.Buffer, class_guid, class_nameW, size, &required_sizeW);
 
@@ -4015,6 +4031,8 @@ BOOL WINAPI SetupDiGetINFClassA(PCSTR inf, LPGUID class_guid, PSTR class_name,
     else
         if(required_size) *required_size = required_sizeW;
 
+    HeapFree(GetProcessHeap(), 0, class_nameW);
+    RtlFreeUnicodeString(&infW);
     return retval;
 }
 




More information about the wine-cvs mailing list