correctly using WdfControlDeviceInitAllocate, WdfControlFinishInitializing and WdfDeviceInitFree

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?

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.

I was completely wrong!
Thanks for response.