[ros-diffs] [janderwald] 37619: - Fix heap corruption and memory leak - patch by Daniel Zimmermann - CID 707 - bug 3905

janderwald at svn.reactos.org janderwald at svn.reactos.org
Mon Nov 24 19:05:52 CET 2008


Author: janderwald
Date: Mon Nov 24 12:05:51 2008
New Revision: 37619

URL: http://svn.reactos.org/svn/reactos?rev=37619&view=rev
Log:
- Fix heap corruption and memory leak
- patch by Daniel Zimmermann
- CID 707
- bug 3905

Modified:
    trunk/reactos/dll/cpl/sysdm/startrec.c

Modified: trunk/reactos/dll/cpl/sysdm/startrec.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/sysdm/startrec.c?rev=37619&r1=37618&r2=37619&view=diff
==============================================================================
--- trunk/reactos/dll/cpl/sysdm/startrec.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/sysdm/startrec.c [iso-8859-1] Mon Nov 24 12:05:51 2008
@@ -62,7 +62,7 @@
 
     /* get Path to freeldr.ini or boot.ini */
     *szSystemDrive = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
-    if (szSystemDrive != NULL)
+    if (*szSystemDrive != NULL)
     {
         dwBufSize = GetEnvironmentVariableW(L"SystemDrive", *szSystemDrive, MAX_PATH);
         if (dwBufSize > MAX_PATH)
@@ -83,15 +83,15 @@
         else if (dwBufSize == 0)
         {
 FailGetSysDrive:
-            HeapFree(GetProcessHeap(), 0, szSystemDrive);
+            HeapFree(GetProcessHeap(), 0, *szSystemDrive);
             *szSystemDrive = NULL;
-            return FALSE;
+            return 0;
         }
 
         return dwBufSize;
     }
 
-    return FALSE;
+    return 0;
 }
 
 static PBOOTRECORD
@@ -454,7 +454,7 @@
     HINF hInf;
 
     dwBufSize = GetSystemDrive(&szSystemDrive);
-    if (!dwBufSize)
+    if (dwBufSize == 0)
         return FALSE;
 
     wcscpy(pStartInfo->szFreeldrIni, szSystemDrive);
@@ -462,6 +462,8 @@
 
     if (PathFileExistsW(pStartInfo->szFreeldrIni))
     {
+        /* free resource previously allocated by GetSystemDrive() */
+        HeapFree(GetProcessHeap(), 0, szSystemDrive);
         /* freeldr.ini exists */
         hInf = SetupOpenInfFileW(pStartInfo->szFreeldrIni,
                                 NULL,
@@ -481,6 +483,9 @@
     /* try load boot.ini settings */
     wcscpy(pStartInfo->szFreeldrIni, szSystemDrive);
     wcscat(pStartInfo->szFreeldrIni, L"\\boot.ini");
+
+    /* free resource previously allocated by GetSystemDrive() */
+    HeapFree(GetProcessHeap(), 0, szSystemDrive);
 
     if (PathFileExistsW(pStartInfo->szFreeldrIni))
     {



More information about the Ros-diffs mailing list