From: Paul Durrant Date: Fri, 6 Jan 2017 15:44:00 +0000 (+0000) Subject: Fix memory leak in __FreePage() X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=f529058c;p=people%2Fpauldu%2Fxenvif.git 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 --- diff --git a/src/xenvif/util.h b/src/xenvif/util.h index e5596e3..8983d4c 100644 --- a/src/xenvif/util.h +++ b/src/xenvif/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,