]> xenbits.xensource.com Git - pvdrivers/win/xeniface.git/commitdiff
Fix memory leak in __FreePage()
authorPaul Durrant <paul.durrant@citrix.com>
Fri, 6 Jan 2017 15:52:26 +0000 (15:52 +0000)
committerPaul Durrant <paul.durrant@citrix.com>
Fri, 6 Jan 2017 15:52:26 +0000 (15:52 +0000)
The pool memory for the MDL also needs to be freed.

Also, generalise __AllocatePage() and __FreePage() to __AllocatePages()
and __FreePages() to allow for multi-page allocations in future.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
src/xeniface/util.h

index 56810e00ee1d8566cd698aea1ee6d111638cee00..b258f9e618c3ac422dd7c98b0462bc54fc378820 100644 (file)
@@ -170,8 +170,8 @@ __FreePoolWithTag(
 }
 
 static FORCEINLINE PMDL
-__AllocatePage(
-    VOID
+__AllocatePages(
+    IN  ULONG           Count
     )
 {
     PHYSICAL_ADDRESS    LowAddress;
@@ -185,7 +185,7 @@ __AllocatePage(
     LowAddress.QuadPart = 0ull;
     HighAddress.QuadPart = ~0ull;
     SkipBytes.QuadPart = 0ull;
-    TotalBytes = (SIZE_T)PAGE_SIZE;
+    TotalBytes = (SIZE_T)PAGE_SIZE * Count;
 
     Mdl = MmAllocatePagesForMdlEx(LowAddress,
                                   HighAddress,
@@ -198,7 +198,7 @@ __AllocatePage(
     if (Mdl == NULL)
         goto fail1;
 
-    if (Mdl->ByteCount < PAGE_SIZE)
+    if (Mdl->ByteCount < TotalBytes)
         goto fail2;
 
     ASSERT((Mdl->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA |
@@ -221,7 +221,7 @@ __AllocatePage(
 
     ASSERT3P(MdlMappedSystemVa, ==, Mdl->MappedSystemVa);
 
-    RtlZeroMemory(MdlMappedSystemVa, PAGE_SIZE);
+    RtlZeroMemory(MdlMappedSystemVa, Mdl->ByteCount);
 
     return Mdl;
 
@@ -240,8 +240,10 @@ fail1:
     return NULL;
 }
 
+#define __AllocatePage()    __AllocatePages(1)
+
 static FORCEINLINE VOID
-__FreePage(
+__FreePages(
     IN PMDL    Mdl
     )
 {
@@ -250,13 +252,14 @@ __FreePage(
     ASSERT(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA);
     MdlMappedSystemVa = Mdl->MappedSystemVa;
 
-    RtlFillMemory(MdlMappedSystemVa, PAGE_SIZE, 0xAA);
-
     MmUnmapLockedPages(MdlMappedSystemVa, Mdl);
 
     MmFreePagesFromMdl(Mdl);
+    ExFreePool(Mdl);
 }
 
+#define __FreePage(_Mdl)    __FreePages(_Mdl)
+
 static FORCEINLINE PCHAR
 __strtok_r(
     IN      PCHAR   Buffer,