Simo made some excellent suggestions on IRC, so I have incorporated them:
First, I changed the interface for be_add_online_cb() so that it will now take a mem_ctx and pass back (if requested) the online_cb object. (This object is now opaque). This way, the callback will be automatically freed if the parent context goes away for any reason.
I removed the be_remove_online_cb() function, so the interface to remove a callback will simply be to call talloc_free() on the opaque object returned from be_add_online_cb. This will allow us to potentially set the same callback function multiple times, with different private data.
New patch attached.