]> git.sesse.net Git - vlc/blobdiff - modules/access_filter/timeshift.c
Check the returned values of malloc.
[vlc] / modules / access_filter / timeshift.c
index 33bc5c2cf38978d7dbf5bedc6c7a675f18589cc9..4e7c32306756b6b34640f4b4a63fe8c3401b6d0a 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 
-#include <stdio.h>
 
 #include <errno.h>
 
@@ -66,6 +69,7 @@ vlc_module_begin();
     add_integer( "timeshift-granularity", 50, NULL, GRANULARITY_TEXT,
                  GRANULARITY_LONGTEXT, VLC_TRUE );
     add_directory( "timeshift-dir", 0, 0, DIR_TEXT, DIR_LONGTEXT, VLC_FALSE );
+        change_unsafe();
     add_bool( "timeshift-force", VLC_FALSE, NULL, FORCE_TEXT, FORCE_LONGTEXT,
               VLC_FALSE );
 vlc_module_end();
@@ -299,7 +303,7 @@ static void Thread( access_t *p_access )
 
         /* Write block */
         if( !p_sys->p_write_list && !p_sys->p_read_list &&
-            p_sys->p_fifo->i_size < TIMESHIFT_FIFO_MAX )
+            block_FifoSize( p_sys->p_fifo ) < TIMESHIFT_FIFO_MAX )
         {
             /* If there isn't too much timeshifted data,
              * write directly to FIFO */
@@ -311,7 +315,7 @@ static void Thread( access_t *p_access )
         block_Release( p_block );
 
         /* Read from file to fill up the fifo */
-        while( p_sys->p_fifo->i_size < TIMESHIFT_FIFO_MIN &&
+        while( block_FifoSize( p_sys->p_fifo ) < TIMESHIFT_FIFO_MIN &&
                !p_access->b_die )
         {
             p_block = ReadBlockFromFile( p_access );
@@ -324,10 +328,10 @@ static void Thread( access_t *p_access )
     msg_Dbg( p_access, "timeshift: no more input data" );
 
     while( !p_access->b_die &&
-           (p_sys->p_read_list || p_sys->p_fifo->i_size) )
+           (p_sys->p_read_list || block_FifoSize( p_sys->p_fifo ) ) )
     {
         /* Read from file to fill up the fifo */
-        while( p_sys->p_fifo->i_size < TIMESHIFT_FIFO_MIN &&
+        while( block_FifoSize( p_sys->p_fifo ) < TIMESHIFT_FIFO_MIN &&
                !p_access->b_die && p_sys->p_read_list )
         {
             p_block = ReadBlockFromFile( p_access );
@@ -423,8 +427,8 @@ static int WriteBlockToFile( access_t *p_access, block_t *p_block )
         if( !file && p_sys->i_files < 2 )
         {
             /* We just can't work with less than 2 buffer files */
-            msg_Err( p_access, "cannot open temporary file '%s' (%s)",
-                     p_sys->psz_filename, strerror(errno) );
+            msg_Err( p_access, "cannot open temporary file '%s' (%m)",
+                     p_sys->psz_filename );
             return VLC_EGENERIC;
         }
         else if( !file ) return VLC_EGENERIC;
@@ -538,7 +542,7 @@ static int Control( access_t *p_access, int i_query, va_list args )
         *pi_int = 0;
         break;
 
-    case ACCESS_SET_PAUSE_STATE: 
+    case ACCESS_SET_PAUSE_STATE:
         break;
 
     /* Forward everything else to the source access */
@@ -556,15 +560,9 @@ static int Control( access_t *p_access, int i_query, va_list args )
 #endif
 static char *GetTmpFilePath( access_t *p_access )
 {
-    char *psz_dir = var_GetString( p_access, "timeshift-dir" );
+    char *psz_dir = var_GetNonEmptyString( p_access, "timeshift-dir" );
     char *psz_filename_base;
 
-    if( ( psz_dir != NULL ) && ( psz_dir[0] == '\0' ) )
-    {
-        free( psz_dir );
-        psz_dir = NULL;
-    }
-
     if( psz_dir == NULL )
     {
 #ifdef WIN32