Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
satip client: fix wrong memory access, call arg cleanups
  • Loading branch information
perexg committed Jun 20, 2016
1 parent e598efc commit 55fec0f
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/input/mpegts/satip/satip_frontend.c
Expand Up @@ -1075,18 +1075,15 @@ satip_frontend_wake_other_waiting

static void
satip_frontend_request_cleanup
( satip_frontend_t *lfe, satip_tune_req_t **_tr )
( satip_frontend_t *lfe, satip_tune_req_t *tr )
{
satip_tune_req_t *tr = *_tr;
if (tr && tr != lfe->sf_req) {
mpegts_pid_done(&tr->sf_pids);
mpegts_pid_done(&tr->sf_pids_tuned);
free(tr);
*_tr = NULL;
}
if (tr == lfe->sf_req_thread)
lfe->sf_req_thread = NULL;

}

static void
Expand Down Expand Up @@ -1151,14 +1148,14 @@ satip_frontend_extra_shutdown
static void
satip_frontend_shutdown
( satip_frontend_t *lfe, const char *name, http_client_t *rtsp,
satip_tune_req_t **tr, tvhpoll_t *efd )
satip_tune_req_t *tr, tvhpoll_t *efd )
{
char b[32];
tvhpoll_event_t ev;
int r, nfds;

if (rtsp->hc_rtsp_stream_id < 0)
return;
goto wake;

snprintf(b, sizeof(b), "/stream=%li", rtsp->hc_rtsp_stream_id);
tvhtrace("satip", "%s - shutdown for %s/%s", name, b, rtsp->hc_rtsp_session ?: "");
Expand All @@ -1167,7 +1164,7 @@ satip_frontend_shutdown
tvhtrace("satip", "%s - bad teardown", b);
} else {
while (1) {
r = http_client_run(rtsp);
r = http_client_run(rtsp);
if (r != HTTP_CON_RECEIVING && r != HTTP_CON_SENDING)
break;
nfds = tvhpoll_wait(efd, &ev, 1, 400);
Expand All @@ -1184,8 +1181,9 @@ satip_frontend_shutdown
}
sbuf_free(&lfe->sf_sbuf);

wake:
pthread_mutex_lock(&lfe->sf_dvr_lock);
satip_frontend_wake_other_waiting(lfe, *tr);
satip_frontend_wake_other_waiting(lfe, tr);
satip_frontend_request_cleanup(lfe, tr);
pthread_mutex_unlock(&lfe->sf_dvr_lock);
}
Expand All @@ -1211,7 +1209,7 @@ satip_frontend_tuning_error ( satip_frontend_t *lfe, satip_tune_req_t *tr )
static void
satip_frontend_close_rtsp
( satip_frontend_t *lfe, const char *name, tvhpoll_t *efd,
http_client_t **rtsp, satip_tune_req_t **tr )
http_client_t *rtsp, satip_tune_req_t *tr )
{
tvhpoll_event_t ev;

Expand All @@ -1221,16 +1219,15 @@ satip_frontend_close_rtsp
ev.data.ptr = NULL;
tvhpoll_rem(efd, &ev, 1);

satip_frontend_shutdown(lfe, name, *rtsp, tr, efd);
satip_frontend_shutdown(lfe, name, rtsp, tr, efd);

memset(&ev, 0, sizeof(ev));
ev.events = TVHPOLL_IN;
ev.fd = lfe->sf_dvr_pipe.rd;
ev.data.ptr = NULL;
tvhpoll_add(efd, &ev, 1);

http_client_close(*rtsp);
*rtsp = NULL;
http_client_close(rtsp);
}

static int
Expand Down Expand Up @@ -1375,8 +1372,11 @@ satip_frontend_input_thread ( void *aux )
rtcp = rtp = NULL;
lfe_master = NULL;

if (rtsp && !lfe->sf_device->sd_fast_switch)
satip_frontend_close_rtsp(lfe, buf, efd, &rtsp, &tr);
if (rtsp && !lfe->sf_device->sd_fast_switch) {
satip_frontend_close_rtsp(lfe, buf, efd, rtsp, tr);
rtsp = NULL;
tr = NULL;
}

if (rtsp)
rtsp->hc_rtp_data_received = NULL;
Expand All @@ -1402,8 +1402,11 @@ satip_frontend_input_thread ( void *aux )

if (!tvheadend_is_running()) { exit_flag = 1; goto done; }
if (rtsp && (getfastmonoclock() - u64_2 > 50000 || /* 50ms */
(start & 2) == 0))
satip_frontend_close_rtsp(lfe, buf, efd, &rtsp, &tr);
(start & 2) == 0)) {
satip_frontend_close_rtsp(lfe, buf, efd, rtsp, tr);
rtsp = NULL;
tr = NULL;
}
if (nfds <= 0) continue;

if (ev[0].data.ptr == NULL) {
Expand Down Expand Up @@ -1446,7 +1449,7 @@ satip_frontend_input_thread ( void *aux )
lfe->mi_display_name((mpegts_input_t*)lfe, buf, sizeof(buf));

pthread_mutex_lock(&lfe->sf_dvr_lock);
satip_frontend_request_cleanup(lfe, &tr);
satip_frontend_request_cleanup(lfe, tr);
lfe->sf_req_thread = tr = lfe->sf_req;
pthread_mutex_unlock(&lfe->sf_dvr_lock);

Expand Down Expand Up @@ -1897,7 +1900,8 @@ satip_frontend_input_thread ( void *aux )
tvhpoll_rem(efd, ev, nfds);

if (exit_flag) {
satip_frontend_shutdown(lfe, buf, rtsp, &tr, efd);
satip_frontend_shutdown(lfe, buf, rtsp, tr, efd);
tr = NULL;
http_client_close(rtsp);
rtsp = NULL;
}
Expand All @@ -1917,7 +1921,7 @@ satip_frontend_input_thread ( void *aux )
goto new_tune;

pthread_mutex_lock(&lfe->sf_dvr_lock);
satip_frontend_request_cleanup(lfe, &tr);
satip_frontend_request_cleanup(lfe, tr);
pthread_mutex_unlock(&lfe->sf_dvr_lock);

if (rtsp)
Expand All @@ -1927,8 +1931,6 @@ satip_frontend_input_thread ( void *aux )
lfe->sf_display_name = NULL;
lfe->sf_curmux = NULL;

satip_frontend_wake_other_waiting(lfe, tr);

return NULL;
#undef PKTS
}
Expand Down

0 comments on commit 55fec0f

Please sign in to comment.