[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH] Fix memory leak in __FreePage()



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@xxxxxxxxxx>
---
 src/xeniface/util.h | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/xeniface/util.h b/src/xeniface/util.h
index 56810e0..b258f9e 100644
--- a/src/xeniface/util.h
+++ b/src/xeniface/util.h
@@ -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,
-- 
2.5.3


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.