Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close mountpoint sockets when leaving relay thread (fixes #3111) #3143

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/plugins/janus_streaming.c
Original file line number Diff line number Diff line change
Expand Up @@ -9316,6 +9316,25 @@ static void *janus_streaming_relay_thread(void *data) {
}
}

/* Close the ports we bound to */
temp = source->media;
while(temp) {
janus_streaming_rtp_source_stream *stream = (janus_streaming_rtp_source_stream *)temp->data;
if(stream->fd[0] > -1)
close(stream->fd[0]);
stream->fd[0] = -1;
if(stream->fd[1] > -1)
close(stream->fd[1]);
stream->fd[1] = -1;
if(stream->fd[2] > -1)
close(stream->fd[2]);
stream->fd[2] = -1;
Comment on lines +9323 to +9331
Copy link
Member

@atoppi atoppi Jan 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit redundant, why not use a simple loop?

	for(int i=0; i<3; i++) {
  		if(stream->fd[i] > -1) {
			close(stream->fd[i]);
  			stream->fd[i] = -1;
		}
	}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since i was small enough and known, it felt easier to do that. Besides, I just copied what we had in the _free callback already.

if(stream->rtcp_fd > -1)
close(stream->rtcp_fd);
stream->rtcp_fd = -1;
temp = temp->next;
}

/* Notify users this mountpoint is done */
janus_mutex_lock(&mountpoint->mutex);
GList *viewer = g_list_first(mountpoint->viewers);
Expand Down