]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
timeshift: reallocate segment on close to release unused tail
authorJaroslav Kysela <perex@perex.cz>
Thu, 17 Dec 2015 15:00:09 +0000 (16:00 +0100)
committerJaroslav Kysela <perex@perex.cz>
Sun, 20 Dec 2015 09:51:59 +0000 (10:51 +0100)
src/timeshift/timeshift_filemgr.c

index db0d8b0d2b916c8036e01a37612ce9f1b67bae71..6204232292ca07b821f961c66ea5e34cf0d81785 100644 (file)
@@ -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(&timeshift_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;