rist_destroy throwing segfault when no peers connected
What I'm doing is just creating a receiver/sender and then after a few seconds destroying it, without sending/receiving data. This causes segmentation faults ocasionally. I debugged it and it seems that the problem is in the function rist_receiver_destroy_local
(and its equivalent for sender):
// Destroy all peers
rist_log_priv(&ctx->common, RIST_LOG_INFO, "Starting Peers cleanup\n");
struct rist_peer *peer, *next;
peer = ctx->common.PEERS;
for (;;) {
if (!peer)
break;
rist_peer_remove(&ctx->common, peer, &next);
peer = next;
}
rist_log_priv(&ctx->common, RIST_LOG_INFO, "Peers cleanup complete\n");
The line that checks if the peer exists before calling rist_peer_remove
is not entering the break in my case, so it's always calling rist_peer_remove with whatever information there is in ctx->common.PEERS
, even when no clients are connected. And the segfault always occur inside that function (in different parts).
Do I understand correctly that if the receiver/sender does not have any client connected, there are no peers and so, that function should never be called? I'm not sure WHY peer is not null if I don't have any clients.
EDIT: upon deeper debugging, it seems that the segfault is actually related to the logging api (I've seen a few tickets about this). I did a quick test replacing all instances of rist_log_priv
and rist_log_priv2
with rist_log_priv3
(that does not require a context pointer in the arguments) and the segfault does not seem to happen anymore.