[vlc-commits] timeshift: delete temporary file as soon as possible
Rémi Denis-Courmont
git at videolan.org
Mon Aug 24 20:14:06 CEST 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Aug 24 20:44:24 2015 +0300| [75799939abfc6b34e9db00b54adfd7d7fceac583] | committer: Rémi Denis-Courmont
timeshift: delete temporary file as soon as possible
This avoids leaking disk space if VLC does not terminate cleanly.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=75799939abfc6b34e9db00b54adfd7d7fceac583
---
src/input/es_out_timeshift.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/input/es_out_timeshift.c b/src/input/es_out_timeshift.c
index d9bd3dc..33a965e 100644
--- a/src/input/es_out_timeshift.c
+++ b/src/input/es_out_timeshift.c
@@ -157,7 +157,9 @@ struct ts_storage_t
ts_storage_t *p_next;
/* */
+#ifdef _WIN32
char *psz_file; /* Filename */
+#endif
size_t i_file_max; /* Max size in bytes */
int64_t i_file_size;/* Current size in bytes */
FILE *p_filew; /* FILE handle for data writing */
@@ -1097,7 +1099,8 @@ static ts_storage_t *TsStorageNew( const char *psz_tmp_path, int64_t i_tmp_size_
if( unlikely(p_storage == NULL) )
return NULL;
- int fd = GetTmpFile( &p_storage->psz_file, psz_tmp_path );
+ char *psz_file;
+ int fd = GetTmpFile( &psz_file, psz_tmp_path );
if( fd == -1 )
{
free( p_storage );
@@ -1108,18 +1111,24 @@ static ts_storage_t *TsStorageNew( const char *psz_tmp_path, int64_t i_tmp_size_
if( p_storage->p_filew == NULL )
{
close( fd );
- vlc_unlink( p_storage->psz_file );
+ vlc_unlink( psz_file );
goto error;
}
- p_storage->p_filer = vlc_fopen( p_storage->psz_file, "rb" );
+ p_storage->p_filer = vlc_fopen( psz_file, "rb" );
if( p_storage->p_filer == NULL )
{
fclose( p_storage->p_filew );
- vlc_unlink( p_storage->psz_file );
+ vlc_unlink( psz_file );
goto error;
}
+#ifndef _WIN32
+ vlc_unlink( psz_file );
+ free( psz_file );
+#else
+ p_storage->psz_file = psz_file;
+#endif
p_storage->p_next = NULL;
/* */
@@ -1140,7 +1149,7 @@ static ts_storage_t *TsStorageNew( const char *psz_tmp_path, int64_t i_tmp_size_
}
return p_storage;
error:
- free( p_storage->psz_file );
+ free( psz_file );
free( p_storage );
return NULL;
}
@@ -1159,8 +1168,10 @@ static void TsStorageDelete( ts_storage_t *p_storage )
fclose( p_storage->p_filer );
fclose( p_storage->p_filew );
+#ifdef _WIN32
vlc_unlink( p_storage->psz_file );
free( p_storage->psz_file );
+#endif
free( p_storage );
}
More information about the vlc-commits
mailing list