From: Jaroslav Kysela Date: Fri, 1 Jan 2016 21:21:00 +0000 (+0100) Subject: timeshift: fix tsf refcounting X-Git-Tag: v4.2.1~1247 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a5085c88986acd6c200abd47f61c4d4e4185b0e2;p=thirdparty%2Ftvheadend.git timeshift: fix tsf refcounting --- diff --git a/src/timeshift/timeshift_reader.c b/src/timeshift/timeshift_reader.c index 2539c66df..c04640236 100644 --- a/src/timeshift/timeshift_reader.c +++ b/src/timeshift/timeshift_reader.c @@ -562,10 +562,11 @@ void *timeshift_reader ( void *p ) { timeshift_t *ts = p; int nfds, end, run = 1, wait = -1, skip_delivered = 0; - timeshift_file_t *cur_file = NULL; + timeshift_file_t *cur_file = NULL, *tmp_file; int cur_speed = 100, keyframe_mode = 0; int64_t mono_now, mono_play_time = 0, mono_last_status = 0; int64_t deliver, deliver0, pause_time = 0, last_time = 0, skip_time = 0; + int64_t i64; streaming_message_t *sm = NULL, *ctrl = NULL; timeshift_index_iframe_t *tsi = NULL; streaming_skip_t *skip = NULL; @@ -641,9 +642,14 @@ void *timeshift_reader ( void *p ) ts->dobuf = 1; skip_delivered = 1; pthread_mutex_lock(&ts->rdwr_mutex); - cur_file = timeshift_filemgr_newest(ts); - cur_file = timeshift_filemgr_get(ts, cur_file ? cur_file->last : - atomic_add_s64(&ts->last_time, 0)); + tmp_file = timeshift_filemgr_newest(ts); + if (tmp_file != NULL) { + i64 = tmp_file->last; + tmp_file->refcount--; + } else { + i64 = atomic_add_s64(&ts->last_time, 0); + } + cur_file = timeshift_filemgr_get(ts, i64); if (cur_file != NULL) { cur_file->roff = cur_file->size; pause_time = cur_file->last; @@ -724,8 +730,12 @@ void *timeshift_reader ( void *p ) /* Live playback (stage1) */ if (ts->state == TS_LIVE) { pthread_mutex_lock(&ts->rdwr_mutex); - cur_file = timeshift_filemgr_newest(ts); - if (cur_file && (cur_file = timeshift_filemgr_get(ts, cur_file->last)) != NULL) { + tmp_file = timeshift_filemgr_newest(ts); + if (tmp_file) { + i64 = tmp_file->last; + tmp_file->refcount--; + } + if (tmp_file && (cur_file = timeshift_filemgr_get(ts, i64)) != NULL) { cur_file->roff = cur_file->size; last_time = cur_file->last; } else {