Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results


Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging

The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.

Check out The OSR Learning Library at:

Freeing physical pages mapped in the MDL

Jay_KumarJay_Kumar Member Posts: 26

Hi All,

I have question regarding freeing of physical pages mapped to MDL using this function MmFreePagesFromMdl.
I have a code flow like this.

1) User mode allocates a memory and invokes IOCTL (Direct_IN)
2) My driver finds the physical pages passed in the MDL structure from IRP
3) Programs the device using the physical pages
4) Then try to deallocate the memory occupied by the physical pages

Does this cause any memory corruption or access violation since the I feel the system also will try to free the physical pages when completing the IRP request.

Any pointer will be appreciated..



  • Mark_RoddyMark_Roddy Member - All Emails Posts: 4,753

    Yeah, you didn't allocate those pages so don't free them.

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 14,831

    You don't own that memory, so of course you are not allowed to free the pages. They will be freed by the owner.

    And please remember that even with METHOD_IN_DIRECT, the first buffer in the DeviceIoControl call is COPIED into kernel memory. It is only the second buffer that is mapped.

    Tim Roberts, [email protected]
    Software Wizard Emeritus

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 13-17 May 2024 Live, Online
Developing Minifilters 1-5 Apr 2024 Live, Online
Internals & Software Drivers 11-15 Mar 2024 Live, Online
Writing WDF Drivers 20-24 May 2024 Live, Online