From 7af06e4d8beedf4a1cf81afefa79c843382805a9 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Mon, 7 Jul 2014 19:55:10 +0200 Subject: [PATCH] iptv: udp - fix the mutex protection for the stop callback --- src/input/mpegts/iptv/iptv.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/input/mpegts/iptv/iptv.c b/src/input/mpegts/iptv/iptv.c index 2bcdf205..b4de0f6d 100644 --- a/src/input/mpegts/iptv/iptv.c +++ b/src/input/mpegts/iptv/iptv.c @@ -237,12 +237,12 @@ iptv_input_stop_mux ( mpegts_input_t *mi, mpegts_mux_instance_t *mmi ) iptv_mux_t *im = (iptv_mux_t*)mmi->mmi_mux; mpegts_network_link_t *mnl; + pthread_mutex_lock(&iptv_lock); + /* Stop */ if (im->im_handler->stop) im->im_handler->stop(im); - pthread_mutex_lock(&iptv_lock); - /* Close file */ if (im->mm_iptv_fd > 0) { udp_close(im->mm_iptv_connection); // removes from poll @@ -292,19 +292,17 @@ iptv_input_thread ( void *aux ) pthread_mutex_lock(&iptv_lock); - /* No longer active */ - if (!im->mm_active) - goto done; - - /* Get data */ - if ((n = im->im_handler->read(im)) < 0) { - tvhlog(LOG_ERR, "iptv", "read() error %s", strerror(errno)); - im->im_handler->stop(im); - goto done; + /* Only when active */ + if (im->mm_active) { + /* Get data */ + if ((n = im->im_handler->read(im)) < 0) { + tvhlog(LOG_ERR, "iptv", "read() error %s", strerror(errno)); + im->im_handler->stop(im); + break; + } + iptv_input_recv_packets(im, n); } - iptv_input_recv_packets(im, n); -done: pthread_mutex_unlock(&iptv_lock); } return NULL;