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:

correctly using WdfControlDeviceInitAllocate, WdfControlFinishInitializing and WdfDeviceInitFree

Ehsan_TaheriEhsan_Taheri Member Posts: 190

It is not directly documented.
But from samples by Microsoft I can guess WdfControlFinishInitializing frees the init structure allocated by WdfControlDeviceInitAllocate.
Again, it is not in the doc for WdfControlDeviceInitAllocate but the sample at the end of the page shows the use of WdfDeviceInitFree in error cases to free the init structure.
But in success case there is no call to WdfDeviceInitFree so I guess WdfControlFinishInitializing does the job.
1. Am I right about this?
2. what happens in case I call WdfControlFinishInitializing and then WdfDeviceInitFree after that? Do I have to manually set the variable containing the return pointer from WdfControlDeviceInitAllocate to NULL to avoid WdfDeviceInitFree being called in error conditions after WdfControlFinishInitializing being called?


  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,376

    WdfDeviceCreate frees the device init structure when successful. If WdfDeviceCreate fails (or you fail somewhere before calling WdfDeviceCreate) then you need to free the structure with WdfDeviceInitFree.

    WdfControlFinishInitializing takes a WDFDEVICE handle so you can't call it until WdfDeviceCreate succeeds.


  • Ehsan_TaheriEhsan_Taheri Member Posts: 190

    I was completely wrong!
    Thanks for response.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

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!
Writing WDF Drivers 7 Dec 2020 LIVE ONLINE
Internals & Software Drivers 25 Jan 2021 LIVE ONLINE
Developing Minifilters 8 March 2021 LIVE ONLINE