[interfacekit] Re: BLooper::SetCommonFilterList() mod
- From: "Marcus Overhagen" <ml@xxxxxxxxxxxx>
- To: interfacekit@xxxxxxxxxxxxx
- Date: Sat, 24 Aug 2002 13:33:22 CEST (+0200)
>
> Hey, all. Thought I would ping for opinions before I did something
> rash. ;) Currently the OBOS and R5 implementations of BLooper will
> segfault if you do this:
>
> BLooper Looper1;
> BLooper Looper2;
> BList* filters =3D new BList;
> filters->AddItem(new BMessageFilter('1234'));
> Looper1.SetCommonFilterList(filters);
> Looper2.SetCommonFilterList(filters);
>
From the BeBook:
SetCommonFilterList() deletes the current filter list and its contents, and
replaces it with filters. All elements in filters must be BMessageFilter
pointers.
>>The BLooper takes ownership of all objects in filters, as well as filters
>>itself.
If filters is NULL, the current list is deleted without a replacement.
CommonFilterList() returns a pointer to the current list. You can examine
the list but you shouldn't modify or delete it.
This clearly indicated that a filter list can only be used with one looper.
> The segfault happens on destruction of Looper1 because Looper2 has
> already deleted filters, leaving us with a dangling pointer. Very bad.
> What I'd like to do is add a check on the first filter of the list to
> see if it belongs to another looper and if it does, go to debugger with
> a message like AddCommonFilter() ("A MessageFilter can only be used
> once.") and then return without setting the list. I could check the
> whole list, but that would be more time consuming and only a real
> pervert would populate a list with filters in different states of
> ownership. ;P
>
> Anyone see any problem with this=3F
No, would be ok for me. Except that there may be programs
already doing it, but since they will crash anyway, just add
the check.
Marcus
Other related posts: