[core,mod_conference] Fix memory leak on clearing down member call by changing way of flushing frame buffer

This commit is contained in:
Jakub Karolczyk 2021-03-10 17:15:04 +00:00 committed by Jakub Karolczyk
parent f9bb8940c2
commit 7dfb7d2292
3 changed files with 37 additions and 26 deletions

View File

@ -1480,6 +1480,7 @@ SWITCH_DECLARE(void) switch_http_parse_qs(switch_http_request_t *request, char *
SWITCH_DECLARE(switch_status_t) switch_frame_buffer_free(switch_frame_buffer_t *fb, switch_frame_t **frameP);
SWITCH_DECLARE(switch_status_t) switch_frame_buffer_dup(switch_frame_buffer_t *fb, switch_frame_t *orig, switch_frame_t **clone);
SWITCH_DECLARE(switch_status_t) switch_frame_buffer_destroy(switch_frame_buffer_t **fbP);
SWITCH_DECLARE(switch_status_t) switch_frame_buffer_flush(switch_frame_buffer_t *fb);
SWITCH_DECLARE(switch_status_t) switch_frame_buffer_create(switch_frame_buffer_t **fbP, switch_size_t qlen);
SWITCH_DECLARE(switch_status_t) switch_frame_buffer_push(switch_frame_buffer_t *fb, void *ptr);
SWITCH_DECLARE(switch_status_t) switch_frame_buffer_trypush(switch_frame_buffer_t *fb, void *ptr);

View File

@ -2306,7 +2306,6 @@ void *SWITCH_THREAD_FUNC conference_video_muxing_write_thread_run(switch_thread_
loops++;
if ((switch_size_t)pop != 1) {
frame = (switch_frame_t *) pop;
if (switch_test_flag(frame, SFF_ENCODED)) {
switch_core_session_write_encoded_video_frame(member->session, frame, 0, 0);
@ -2330,16 +2329,8 @@ void *SWITCH_THREAD_FUNC conference_video_muxing_write_thread_run(switch_thread_
switch_frame_buffer_free(member->fb, &frame);
}
}
}
while (switch_frame_buffer_trypop(member->fb, &pop) == SWITCH_STATUS_SUCCESS) {
if (pop) {
if ((switch_size_t)pop != 1) {
frame = (switch_frame_t *) pop;
switch_frame_buffer_free(member->fb, &frame);
}
}
}
switch_frame_buffer_flush(member->fb);
switch_thread_rwlock_unlock(member->rwlock);

View File

@ -290,11 +290,30 @@ SWITCH_DECLARE(int) switch_frame_buffer_size(switch_frame_buffer_t *fb)
return switch_queue_size(fb->queue);
}
SWITCH_DECLARE(switch_status_t) switch_frame_buffer_flush(switch_frame_buffer_t *fb)
{
void *pop;
switch_frame_t *frame;
switch_status_t status = SWITCH_STATUS_FALSE;
if (fb) {
while ((status = switch_frame_buffer_trypop(fb, &pop)) == SWITCH_STATUS_SUCCESS) {
if (pop) {
frame = (switch_frame_t *) pop;
switch_frame_buffer_free(fb, &frame);
}
}
}
return status;
}
SWITCH_DECLARE(switch_status_t) switch_frame_buffer_destroy(switch_frame_buffer_t **fbP)
{
switch_frame_buffer_t *fb = *fbP;
switch_memory_pool_t *pool;
*fbP = NULL;
switch_frame_buffer_flush(fb);
pool = fb->pool;
switch_core_destroy_memory_pool(&pool);