Deleting Contexts

Every context that is set by a successful call to FltSetXxxContext must eventually be deleted. However, the filter manager deletes contexts automatically when the objects that they are attached to are deleted, when a minifilter driver instance is detached from a volume, or when the minifilter driver is unloaded. Thus, it is rarely necessary for a minifilter driver to explicitly delete a context.

A minifilter driver can delete a context by calling FltDeleteXxxContext, where Xxx is the context type, or by calling FltDeleteContext.

A context can be deleted only if it is currently set for an object. A context cannot be deleted if it has not yet been set, or if it has already been replaced by a successful call to FltSetXxxContext.

In the call to FltDeleteXxxContext, the old context is returned in the OldContext parameter, if it is non-NULL. If the OldContext parameter is NULL, the filter manager decrements the reference count on the context, which is then freed unless the minifilter driver has an outstanding reference on it.

The following code example shows how to delete a stream context:


status = FltDeleteStreamContext(
 FltObjects->Instance,      //Instance
 FltObjects->FileObject,    //FileObject
           &oldContext);              //OldContext
...
if (oldContext != NULL) {
 FltReleaseContext(oldContext);
}

In this example, FltDeleteStreamContext removes the stream context from the stream, but it does not decrement the context's reference count, because the OldContext parameter is non-NULL. FltDeleteStreamContext returns the address of the deleted context in the OldContext parameter. After performing any needed processing, the caller must release the deleted context by calling FltReleaseContext.

 

 

Send comments about this topic to Microsoft

Show:
© 2014 Microsoft