From: Jaroslav Kysela Date: Thu, 17 Dec 2015 15:00:09 +0000 (+0100) Subject: timeshift: reallocate segment on close to release unused tail X-Git-Tag: v4.2.1~1295 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c9212c32fc6657c09b01f1fa7bf6a009235b3aaa;p=thirdparty%2Ftvheadend.git timeshift: reallocate segment on close to release unused tail --- diff --git a/src/timeshift/timeshift_filemgr.c b/src/timeshift/timeshift_filemgr.c index db0d8b0d2..620423229 100644 --- a/src/timeshift/timeshift_filemgr.c +++ b/src/timeshift/timeshift_filemgr.c @@ -151,6 +151,7 @@ int timeshift_filemgr_makedirs ( int index, char *buf, size_t len ) */ void timeshift_filemgr_close ( timeshift_file_t *tsf ) { + uint8_t *ram; ssize_t r = timeshift_write_eof(tsf); if (r > 0) { tsf->size += r; @@ -158,6 +159,14 @@ void timeshift_filemgr_close ( timeshift_file_t *tsf ) if (tsf->ram) atomic_add_u64(×hift_total_ram_size, r); } + if (tsf->ram) { + /* maintain unused memory block */ + ram = realloc(tsf->ram, tsf->woff); + if (ram) { + tsf->ram = ram; + tsf->ram_size = tsf->woff; + } + } if (tsf->wfd >= 0) close(tsf->wfd); tsf->wfd = -1;