X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Finput%2Fstream.c;h=8449a09fafb5a5891a09fc9b18e1037041c28b11;hb=c482de120b992a1c7d6f84a94c90d1b3314327f0;hp=8b831246c6b704172f28919f3356bcfef214064f;hpb=cc3bd152f5d2166087b9e19b962e3ace06bd12ea;p=vlc diff --git a/src/input/stream.c b/src/input/stream.c index 8b831246c6..8449a09faf 100644 --- a/src/input/stream.c +++ b/src/input/stream.c @@ -21,6 +21,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include "input_internal.h" @@ -199,7 +203,7 @@ stream_t *__stream_UrlNew( vlc_object_t *p_parent, const char *psz_url ) char psz_dup[strlen (psz_url) + 1]; strcpy (psz_dup, psz_url);; - MRLSplit( p_parent, psz_dup, &psz_access, &psz_demux, &psz_path ); + MRLSplit( psz_dup, &psz_access, &psz_demux, &psz_path ); /* Now try a real access */ p_access = access2_New( p_parent, psz_access, psz_demux, psz_path, 0 ); @@ -224,7 +228,7 @@ stream_t *stream_AccessNew( access_t *p_access, vlc_bool_t b_quick ) { stream_t *s = vlc_stream_create( VLC_OBJECT(p_access) ); stream_sys_t *p_sys; - char *psz_list; + char *psz_list = NULL; if( !s ) return NULL; @@ -237,6 +241,11 @@ stream_t *stream_AccessNew( access_t *p_access, vlc_bool_t b_quick ) s->pf_destroy = AStreamDestroy; s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) ); + if( p_sys == NULL ) + { + msg_Err( s, "Out of memory when allocating stream_sys_t" ); + goto error; + } /* UTF16 and UTF32 text file conversion */ s->i_char_width = 1; @@ -267,11 +276,22 @@ stream_t *stream_AccessNew( access_t *p_access, vlc_bool_t b_quick ) if( (psz_list = var_CreateGetString( s, "input-list" )) && *psz_list ) { access_entry_t *p_entry = malloc( sizeof(access_entry_t) ); + if( p_entry == NULL ) + { + msg_Err( s, "Out of memory when allocating access_entry_t" ); + goto error; + } char *psz_name, *psz_parser = psz_name = psz_list; p_sys->p_list_access = p_access; p_entry->i_size = p_access->info.i_size; p_entry->psz_path = strdup( p_access->psz_path ); + if( p_entry->psz_path == NULL ) + { + msg_Err( s, "Out of memory when duplicating p_access->psz_path" ); + free( p_entry ); + goto error; + } TAB_APPEND( p_sys->i_list, p_sys->list, p_entry ); msg_Dbg( p_access, "adding file `%s', ("I64Fd" bytes)", p_entry->psz_path, p_access->info.i_size ); @@ -298,6 +318,11 @@ stream_t *stream_AccessNew( access_t *p_access, vlc_bool_t b_quick ) psz_name, p_tmp->info.i_size ); p_entry = malloc( sizeof(access_entry_t) ); + if( p_entry == NULL ) + { + msg_Err( p_access, "Out of memory when allocating access_entry_t" ); + goto error; + } p_entry->i_size = p_tmp->info.i_size; p_entry->psz_path = psz_name; TAB_APPEND( p_sys->i_list, p_sys->list, p_entry ); @@ -309,7 +334,7 @@ stream_t *stream_AccessNew( access_t *p_access, vlc_bool_t b_quick ) if( psz_name ) psz_name++; } } - if( psz_list ) free( psz_list ); + FREENULL( psz_list ); /* Peek */ p_sys->i_peek = 0; @@ -348,6 +373,12 @@ stream_t *stream_AccessNew( access_t *p_access, vlc_bool_t b_quick ) p_sys->stream.i_offset = 0; p_sys->stream.i_tk = 0; p_sys->stream.p_buffer = malloc( STREAM_CACHE_SIZE ); + if( p_sys->stream.p_buffer == NULL ) + { + msg_Err( s, "Out of memory when allocating stream cache (%d bytes)", + STREAM_CACHE_SIZE ); + goto error; + } p_sys->stream.i_used = 0; access2_Control( p_access, ACCESS_GET_MTU, &p_sys->stream.i_read_size ); @@ -386,9 +417,13 @@ error: { free( p_sys->stream.p_buffer ); } + while( p_sys->i_list > 0 ) + free( p_sys->list[--(p_sys->i_list)] ); + free( p_sys->list ); + free( psz_list ); free( s->p_sys ); vlc_object_detach( s ); - vlc_object_destroy( s ); + vlc_object_release( s ); return NULL; } @@ -417,7 +452,7 @@ static void AStreamDestroy( stream_t *s ) } free( s->p_sys ); - vlc_object_destroy( s ); + vlc_object_release( s ); } static void UStreamDestroy( stream_t *s ) @@ -556,6 +591,10 @@ static int AStreamControl( stream_t *s, int i_query, va_list args ) } return access2_vaControl( p_access, i_int, args ); + case STREAM_GET_CONTENT_TYPE: + return access2_Control( p_access, ACCESS_GET_CONTENT_TYPE, + va_arg( args, char ** ) ); + default: msg_Err( s, "invalid stream_vaControl query=0x%x", i_query ); return VLC_EGENERIC; @@ -691,8 +730,8 @@ static int AStreamReadBlock( stream_t *s, void *p_read, int i_read ) p_sys->block.i_offset = 0; p_sys->block.p_current = p_sys->block.p_current->p_next; } - /*Get a new block */ - if( AStreamRefillBlock( s ) ) + /*Get a new block if needed */ + if( !p_sys->block.p_current && AStreamRefillBlock( s ) ) { break; } @@ -866,10 +905,8 @@ static int AStreamSeekBlock( stream_t *s, int64_t i_pos ) /* Refill a block */ if( AStreamRefillBlock( s ) ) - { - msg_Err( s, "cannot re fill buffer" ); return VLC_EGENERIC; - } + /* Update stat */ p_sys->stat.i_seek_time += i_end - i_start; p_sys->stat.i_seek_count++; @@ -881,10 +918,8 @@ static int AStreamSeekBlock( stream_t *s, int64_t i_pos ) while( p_sys->block.i_start + p_sys->block.i_size < i_pos ) { if( AStreamRefillBlock( s ) ) - { - msg_Err( s, "can't read enough data in seek" ); return VLC_EGENERIC; - } + while( p_sys->block.p_current && p_sys->i_pos + p_sys->block.p_current->i_buffer < i_pos ) { @@ -896,7 +931,6 @@ static int AStreamSeekBlock( stream_t *s, int64_t i_pos ) p_sys->block.i_offset = i_pos - p_sys->i_pos; p_sys->i_pos = i_pos; - /* TODO read data */ return VLC_SUCCESS; } @@ -1480,7 +1514,7 @@ char * stream_ReadLine( stream_t *s ) var_SetString( p_input, "subsdec-encoding", "UTF-8" ); vlc_object_release( p_input ); } - if( psz_encoding ) free( psz_encoding ); + free( psz_encoding ); } } @@ -1552,6 +1586,11 @@ char * stream_ReadLine( stream_t *s ) { i_data = (psz_eol - (char *)p_data) + 1; p_line = realloc( p_line, i_line + i_data + s->i_char_width ); /* add \0 */ + if( !p_line ) + { + msg_Err( s, "Out of memory when reallocating p_line" ); + goto error; + } i_data = stream_Read( s, &p_line[i_line], i_data ); if( i_data <= 0 ) break; /* Hmmm */ i_line += i_data - s->i_char_width; /* skip \n */; @@ -1563,6 +1602,11 @@ char * stream_ReadLine( stream_t *s ) /* Read data (+1 for easy \0 append) */ p_line = realloc( p_line, i_line + STREAM_PROBE_LINE + s->i_char_width ); + if( !p_line ) + { + msg_Err( s, "Out of memory when reallocating p_line" ); + goto error; + } i_data = stream_Read( s, &p_line[i_line], STREAM_PROBE_LINE ); if( i_data <= 0 ) break; /* Hmmm */ i_line += i_data; @@ -1586,7 +1630,11 @@ char * stream_ReadLine( stream_t *s ) /* iconv */ psz_new_line = malloc( i_line ); - + if( psz_new_line == NULL ) + { + msg_Err( s, "Out of memory when allocating psz_new_line" ); + goto error; + } i_in = i_out = (size_t)i_line; p_in = p_line; p_out = psz_new_line; @@ -1611,8 +1659,10 @@ char * stream_ReadLine( stream_t *s ) return p_line; } +error: + /* We failed to read any data, probably EOF */ - if( p_line ) free( p_line ); + free( p_line ); if( s->conv != (vlc_iconv_t)(-1) ) vlc_iconv_close( s->conv ); return NULL; }