[ros-diffs] [cgutman] 35076: - Fail if we can't allocate memory - Fix a memory leak - Also resize the buffer on STATUS_BUFFER_OVERFLOW

cgutman at svn.reactos.org cgutman at svn.reactos.org
Sun Aug 3 20:02:10 CEST 2008


Author: cgutman
Date: Sun Aug  3 13:02:10 2008
New Revision: 35076

URL: http://svn.reactos.org/svn/reactos?rev=35076&view=rev
Log:
 - Fail if we can't allocate memory
 - Fix a memory leak
 - Also resize the buffer on STATUS_BUFFER_OVERFLOW

Modified:
    branches/aicom-network-fixes/drivers/network/tcpip/datalink/lan.c

Modified: branches/aicom-network-fixes/drivers/network/tcpip/datalink/lan.c
URL: http://svn.reactos.org/svn/reactos/branches/aicom-network-fixes/drivers/network/tcpip/datalink/lan.c?rev=35076&r1=35075&r2=35076&view=diff
==============================================================================
--- branches/aicom-network-fixes/drivers/network/tcpip/datalink/lan.c [iso-8859-1] (original)
+++ branches/aicom-network-fixes/drivers/network/tcpip/datalink/lan.c [iso-8859-1] Sun Aug  3 13:02:10 2008
@@ -839,6 +839,8 @@
         ExAllocatePool(NonPagedPool, sizeof(KEY_BASIC_INFORMATION));
     ULONG KbioLength = sizeof(KEY_BASIC_INFORMATION), ResultLength;
 
+    if( !Kbio ) return STATUS_INSUFFICIENT_RESOURCES;
+
     RtlInitUnicodeString
         (&EnumKeyName, CCS_ROOT L"\\Control\\Class\\" TCPIP_GUID);
 
@@ -847,6 +849,7 @@
     if( !NT_SUCCESS(Status) ) {
         TI_DbgPrint(DEBUG_DATALINK,("Couldn't open Enum key %wZ: %x\n",
                                     &EnumKeyName, Status));
+        ExFreePool( Kbio );
         return Status;
     }
 
@@ -854,7 +857,7 @@
         Status = ZwEnumerateKey( EnumKey, i, KeyBasicInformation,
                                  Kbio, KbioLength, &ResultLength );
 
-        if( Status == STATUS_BUFFER_TOO_SMALL ) {
+        if( Status == STATUS_BUFFER_TOO_SMALL || Status == STATUS_BUFFER_OVERFLOW ) {
             ExFreePool( Kbio );
             KbioLength = ResultLength;
             Kbio = ExAllocatePool( NonPagedPool, KbioLength );
@@ -864,6 +867,7 @@
 
             if( !NT_SUCCESS(Status) ) {
                 TI_DbgPrint(DEBUG_DATALINK,("Couldn't enum key child %d\n", i));
+                ExFreePool( Kbio );
                 return Status;
             }
         }
@@ -877,6 +881,7 @@
                 ( &EnumKeyName, &TargetKeyName, Name, DeviceDesc );
             if( NT_SUCCESS(Status) ) {
                 NtClose( EnumKey );
+                ExFreePool( Kbio );
                 return Status;
             } else Status = STATUS_SUCCESS;
         }
@@ -885,6 +890,7 @@
     RtlInitUnicodeString( DeviceDesc, L"" );
     AppendUnicodeString( DeviceDesc, &TargetKeyName, FALSE );
     NtClose( EnumKey );
+    ExFreePool( Kbio );
     return STATUS_UNSUCCESSFUL;
 }
 



More information about the Ros-diffs mailing list