Instance context pointer in stream handle context.

Hello All,

Is it right way to store instance context pointer in stream handle context? if yes then do i need to reference/dereference instance context pointer whenever i used through stream handle context?

Thanks in advance,
Vishal

I would say that should not be an issue, but as a rule of thumb and just for consistency reasons whenever I use a pointer of any type of object I keep it referenced for the time I use it, and I release it in the cleanup routine or when I don’t use it anymore. Call it self defense mechanism.

For example in your case, even though I don’t see a scenario where you would have a valid StreamHandleCtx and an invalid InstanceCtx because the instance is gone, I would still keep the InstanceCtx referenced in the StreamHandleCtx just because that’s how things usually work in Windows, you have a valid pointer to some object, that is referenced.

Good luck.

Yeah, I agree with this point, that when you store a pointer in a
structure, take a reference. It’s easier to know that “every pointer has a
reference” than to keep track of all the cases where you don’t need one.
Especially when one year down the line you try to debug something and can’t
remember which pointers have references and which don’t.

However, if you do take a reference at the time you store it in the
StreamHandleContext then you don’t need to reference and then dereference
when using it, you can just dereference at the end. Pay attention however
if you pass this pointer to some other thread or any other data structure,
in which case you will need to take a reference (makes sense, as there’s a
new copy of the pointer)…

On the other hand, for most operations (like when your callbacks get
called, for example pre/postCreate or pre/postRead or whatever) you’ll find
there is a FLT_RELATED_OBJECT structure passed in (
https://msdn.microsoft.com/en-us/library/windows/hardware/ff544816(v=vs.85).aspx)
which contains a PFLT_INSTANCE pointer you can use for the duration of the
callback. So you might not necessarily need to store it in the
StreamHandleContext (you might still chose to do so if you ever use the
StreamHandleContext in a different way, like for example you have a list of
all the StreamHandleContexts your filter is using for some reason).

Thanks,
Alex.

On Thu, May 7, 2015 at 4:09 AM, wrote:

> I would say that should not be an issue, but as a rule of thumb and just
> for consistency reasons whenever I use a pointer of any type of object I
> keep it referenced for the time I use it, and I release it in the cleanup
> routine or when I don’t use it anymore. Call it self defense mechanism.
>
> For example in your case, even though I don’t see a scenario where you
> would have a valid StreamHandleCtx and an invalid InstanceCtx because the
> instance is gone, I would still keep the InstanceCtx referenced in the
> StreamHandleCtx just because that’s how things usually work in Windows, you
> have a valid pointer to some object, that is referenced.
>
> Good luck.
>
> —
> NTFSD is sponsored by OSR
>
> OSR is hiring!! Info at http://www.osr.com/careers
>
> For our schedule of debugging and file system seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Thanks everyone for the help.