RFC: talloc contexts / automatic free at select loop

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Neels Hofmeyr nhofmeyr at sysmocom.de
Thu Mar 21 01:24:30 UTC 2019


Talking of features, another idea comes to mind: freeing of FSM instances. I
more often than not have the problem that a child FSM is freeing, telling the
parent about it, then the parent decides to free because the child's result
signalled some end, and then we have a double free because the child was
allocated with the parent as talloc context, the parent has just deallocated,
but after the child's cleanup is through, the fsm code wants to also deallocate
the child. In these situations I so far need to introduce checks that prevent
the parent from freeing until the children are completely finished with their
actions -- for example, avoid signalling end from the cleanup function or event
handling yet, instead completely rely on the parent_term_event, which is
dispatched only after the child was freed. With a volatile context, when an FSM
instance should go away I could reparent it to the volatile context, it will be
cleaned up once all event handling is through, and I avoid running into double
free by accident. It would probably have to be integrated in the fsm.c
deallocation code.


On Wed, Mar 20, 2019 at 12:54:11PM +0100, Pau Espin Pedrol wrote:
> But I have the feeling it really adds unneeded extra complexity and
> scenarios to take care in the code.

On the contrary, it might require some thinking about contexts once at a few
pivotal points -- AFAICT it only becomes complex with wqueues, and I have the
impression we could fairly easily handle this only once in the wqueue API
(reparent when adding to or removing from a wqueue) so that callers are
actually going to be relieved of all thinking about msgb scoping.  The benefit
on the other hand: I am quite sure that we still have a whole score of mem
leaks / use after free bugs in lots of error handling code paths, which no-one
has noticed and no-one is fixing. With a volatile talloc context approach we
can swat *all* of those bugs by design. We trade a limited amount of brain work
for, theoretically, an inifnite amount of hidden bugs getting fixed.

> IMHO we should be fine using regular global context (and freeing stuff
> around) together with static/stack buffers when possible.

These static buffers have so many various ways of shooting yourself in the
foot, it is very desirable to get rid of them. The idea for me is to achieve
less complexity in using the API. A volatile context is the means to that.



...are we talking about a libosmocore 2.0 now?

~N

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.osmocom.org/pipermail/openbsc/attachments/20190321/697ba654/attachment.bin>


More information about the OpenBSC mailing list