Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
timeshift: fix little memory leak
  • Loading branch information
perexg committed Dec 30, 2015
1 parent 4eb0709 commit a8695cd
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/timeshift/timeshift_reader.c
Expand Up @@ -396,6 +396,8 @@ static int _timeshift_read
ssize_t r;
off_t off;

*sm = NULL;

if (tsf) {

/* Open file */
Expand Down Expand Up @@ -455,21 +457,21 @@ static int _timeshift_read
* Flush all data to live
*/
static int _timeshift_flush_to_live
( timeshift_t *ts, timeshift_file_t **cur_file,
streaming_message_t **sm, int *wait )
( timeshift_t *ts, timeshift_file_t **cur_file, int *wait )
{
streaming_message_t *sm;

time_t pts = 0;
while (*cur_file) {
if (_timeshift_read(ts, cur_file, sm, wait) == -1)
if (_timeshift_read(ts, cur_file, &sm, wait) == -1)
return -1;
if (!*sm) break;
if ((*sm)->sm_type == SMT_PACKET) {
pts = ((th_pkt_t*)(*sm)->sm_data)->pkt_pts;
if (!sm) break;
if (sm->sm_type == SMT_PACKET) {
pts = ((th_pkt_t*)sm->sm_data)->pkt_pts;
tvhlog(LOG_DEBUG, "timeshift", "ts %d deliver %"PRId64" pts=%"PRItime_t,
ts->id, (*sm)->sm_time, pts);
ts->id, sm->sm_time, pts);
}
streaming_target_deliver2(ts->output, *sm);
*sm = NULL;
streaming_target_deliver2(ts->output, sm);
}
return 0;
}
Expand Down Expand Up @@ -766,9 +768,10 @@ void *timeshift_reader ( void *p )
mono_play_time = mono_now;

/* Clear existing packet */
if (sm)
if (sm) {
streaming_msg_free(sm);
sm = NULL;
sm = NULL;
}
} else {
skip = NULL;
}
Expand Down Expand Up @@ -829,6 +832,12 @@ void *timeshift_reader ( void *p )
end = _timeshift_do_skip(ts, req_time, last_time, &cur_file, &tsi);
}

/* Clear old message */
if (sm) {
streaming_msg_free(sm);
sm = NULL;
}

/* Find packet */
if (_timeshift_read(ts, &cur_file, &sm, &wait) == -1) {
pthread_mutex_unlock(&ts->state_mutex);
Expand Down Expand Up @@ -901,7 +910,7 @@ void *timeshift_reader ( void *p )
tvhtrace("timeshift", "reader - set TS_LIVE");

/* Flush timeshift buffer to live */
if (_timeshift_flush_to_live(ts, &cur_file, &sm, &wait) == -1)
if (_timeshift_flush_to_live(ts, &cur_file, &wait) == -1)
break;

/* Flush write / backlog queues */
Expand Down

0 comments on commit a8695cd

Please sign in to comment.