janus-gateway
janus-gateway copied to clipboard
videoroom: Release some references created by remote publishers
~~Fixed some cases where the rtp_forwarders
map was created without the destructor function. This resulted in the forwarders not being released when the publisher got destroyed.~~
I don't think that's wise: the map you see in the publisher's struct is only a shallow reference, since the actual map is stored in the publisher_stream struct, and we do have the janus_rtp_forwarder_destroy
callback for the hashtable there. We risk a double free with the additions you put there I believe, or access to broken memory if the instance was destroyed already.
Thanks for your feedback. I had a problem where the forwarders were not released properly when my controller websocket connection was closed and the patch fixed this.
So maybe my problem must be fixed differently - I'll do some more tests and provide an update here.
forwarders were not released properly when my controller websocket connection was closed
I'd check if the cause is that there are publisher streams (and maybe entire publishers) whose references never get to zero causing their forwarders not to be destroyed either. Did you check by uncommenting the REFCOUNT_DEBUG
define in refcount.h
already? That will enable refcount debugging, which will make logs much more verbose, but will allow you to track references as they go up and down, and will print a summary of what's still there at shutdown (after you try a clean shutdown, that is, so after you closed all sessions/handles properly and shut Janus down expecting everything to be deallocated already).