From c66d27c55588b0ab3406ce4729348beec3aab536 Mon Sep 17 00:00:00 2001 From: Andrew Nguyen Date: Sat, 15 Jan 2011 02:28:37 -0600 Subject: [PATCH] setupapi: Fix some memory leaks in SetupDiGetINFClassA. Spotted with Valgrind. --- dlls/setupapi/devinst.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index 1d318fe3c8e..5b8fb3cc1b6 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; } -- 2.11.4.GIT