There is probably a race between Detach() method and your other functions.
You need to debug the problem and to unilize it correctly.
A few hints to write your filter correctly:
- Upon SetSockets() you should store the pointers to the sockets and call
AddRef as you did.
- In Detach() you should set NULL in members that stored those pointers to
the sockets and you should release the reference (that was a correct thing
to do).
- You should protect members, for example with critical section.
For example,
Class *** : public IFWXDataFilter
{
....
IFWXSocket * m_p1;
....
***(): m_p1(NULL) {
...
}
....
};
***::SetSockets(IFWXSocket * p1, ...)
{
...
p1->AddRef();
Lock();
ASSERT(NULL == m_p1);
m_p1 = p1;
Unlock();
...
}
***:

etach()
{
IFWXSocket * p1 = NULL;
...
Lock();
p1 = m_p1;
m_p1 = NULL;
Unlock();
if (p1) {
p1->Release();
}
...
}
***::AnyOtherFunction()
{
IFWXSocket * p1 = NULL;
...
Lock();
if (m_p1) {
p1 = m_p1;
p1->AddRef();
}
Unlock();
// safely use p1 if it is not NULL
...
}