Hello,
I found i can not delete the device object right away with
IoDeleteDevice sometimes though it is created by my driver because
someone else is holding reference to it. Or bugcheck rises. Scheduling
a work item to delete the device works fine, but it really looks ugly.
Can I use ObDeferenceObjectByXXX to delete the device object? My system
is NT4 sp6.
woodhead
“zhiming” wrote in message news:xxxxx@ntdev…
>
> I found i can not delete the device object right away with
> IoDeleteDevice sometimes though it is created by my driver because
> someone else is holding reference to it. Or bugcheck rises. Scheduling
> a work item to delete the device works fine, but it really looks ugly.
> Can I use ObDeferenceObjectByXXX to delete the device object? My system
> is NT4 sp6.
In short, no. Absolutely not.
In long…
If somebody ELSE is holding a reference to your device object, and YOU
artificially decrement the reference count with ObDeref, the object will be
returned to pool. When it’s returned to pool, that same memory could be
re-used for a different object or data structure for some OTHER driver. The
original holder of the reference on your (now deleted) device object
eventually will decrement the reference count, but since your device object
has been returned to pool and is now some other data structure, what this
accomplishes is decrementing a random ULONG in memory by one. This is a
pool scribble, and will eventually cause a system crash that will be almost
impossible to find.
So, no. Please.
Peter
OSR