Commit e2e0f4d6 authored by Gildas Bazin's avatar Gildas Bazin

* ALL: fixed a handful of bugs and memory leaks.

parent 35e0d027
...@@ -154,7 +154,10 @@ static int Demux( demux_t *p_demux ) ...@@ -154,7 +154,10 @@ static int Demux( demux_t *p_demux )
p_xml = p_sys->p_xml = xml_Create( p_demux ); p_xml = p_sys->p_xml = xml_Create( p_demux );
if( !p_xml ) return -1; if( !p_xml ) return -1;
stream_ReadLine( p_demux->s ); psz_elname = stream_ReadLine( p_demux->s );
if( psz_elname ) free( psz_elname );
psz_elname = 0;
p_xml_reader = xml_ReaderCreate( p_xml, p_demux->s ); p_xml_reader = xml_ReaderCreate( p_xml, p_demux->s );
if( !p_xml_reader ) return -1; if( !p_xml_reader ) return -1;
p_sys->p_xml_reader = p_xml_reader; p_sys->p_xml_reader = p_xml_reader;
......
...@@ -166,31 +166,22 @@ static xml_reader_t *ReaderCreate( xml_t *p_xml, stream_t *s ) ...@@ -166,31 +166,22 @@ static xml_reader_t *ReaderCreate( xml_t *p_xml, stream_t *s )
{ {
xml_reader_t *p_reader; xml_reader_t *p_reader;
char *p_buffer; char *p_buffer;
int i_pos,i_size,i_buffer = 5000; int i_size, i_pos = 0, i_buffer = 2048;
XTag *p_root; XTag *p_root;
/* Open and read file */ /* Open and read file */
p_buffer = malloc( i_buffer + 1 ); p_buffer = malloc( i_buffer );
if( p_buffer == NULL ) if( p_buffer == NULL ) return NULL;
return NULL;
i_pos = 0; while( ( i_size = stream_Read( s, &p_buffer[i_pos], 2048 ) ) == 2048 )
i_size = 0;
while( i_pos < i_buffer )
{ {
i_size = stream_Read( s, &p_buffer[i_pos], 5000 );
i_pos += i_size; i_pos += i_size;
if( i_size < 5000 ) i_buffer += i_size;
break; /* we're done */ p_buffer = realloc( p_buffer, i_buffer );
else
{
i_buffer += 5000;
p_buffer = realloc( p_buffer, i_buffer * sizeof( char *) );
}
} }
p_buffer[ i_pos ] = 0; p_buffer[ i_pos + i_size ] = 0; /* 0 terminated string */
if( !i_buffer ) if( i_pos + i_size == 0 )
{ {
msg_Dbg( p_xml, "empty xml" ); msg_Dbg( p_xml, "empty xml" );
free( p_buffer ); free( p_buffer );
......
...@@ -186,7 +186,7 @@ static int ASeek( stream_t *s, int64_t i_pos ); ...@@ -186,7 +186,7 @@ static int ASeek( stream_t *s, int64_t i_pos );
/**************************************************************************** /****************************************************************************
* stream_AccessNew: create a stream from a access * stream_UrlNew: create a stream from a access
****************************************************************************/ ****************************************************************************/
stream_t *__stream_UrlNew( vlc_object_t *p_parent, const char *psz_url ) stream_t *__stream_UrlNew( vlc_object_t *p_parent, const char *psz_url )
{ {
...@@ -194,32 +194,29 @@ stream_t *__stream_UrlNew( vlc_object_t *p_parent, const char *psz_url ) ...@@ -194,32 +194,29 @@ stream_t *__stream_UrlNew( vlc_object_t *p_parent, const char *psz_url )
access_t *p_access; access_t *p_access;
stream_t *p_res; stream_t *p_res;
if( !psz_url ) return 0;
psz_dup = strdup( psz_url ); psz_dup = strdup( psz_url );
MRLSplit( p_parent, psz_dup, &psz_access, &psz_demux, &psz_path ); MRLSplit( p_parent, psz_dup, &psz_access, &psz_demux, &psz_path );
/* Now try a real access */ /* Now try a real access */
p_access = access2_New( p_parent, psz_access, NULL, p_access = access2_New( p_parent, psz_access, psz_demux, psz_path, 0 );
psz_path, VLC_FALSE ); free( psz_dup );
if( p_access == NULL ) if( p_access == NULL )
{ {
msg_Err( p_parent, "no suitable access module for `%s'", psz_url ); msg_Err( p_parent, "no suitable access module for `%s'", psz_url );
free( psz_dup );
return NULL; return NULL;
} }
p_res = stream_AccessNew( p_access, VLC_TRUE );
if( p_res ) if( !( p_res = stream_AccessNew( p_access, VLC_TRUE ) ) )
{
p_res->pf_destroy = UStreamDestroy;
free( psz_dup );
return p_res;
}
else
{ {
access2_Delete( p_access ); access2_Delete( p_access );
return NULL;
} }
free( psz_dup );
return NULL; p_res->pf_destroy = UStreamDestroy;
return p_res;
} }
stream_t *stream_AccessNew( access_t *p_access, vlc_bool_t b_quick ) stream_t *stream_AccessNew( access_t *p_access, vlc_bool_t b_quick )
......
...@@ -116,13 +116,17 @@ playlist_item_t *__playlist_ItemCopy( vlc_object_t *p_obj, ...@@ -116,13 +116,17 @@ playlist_item_t *__playlist_ItemCopy( vlc_object_t *p_obj,
return NULL; return NULL;
} }
memcpy( p_res, p_item, sizeof(playlist_item_t) ); *p_res = *p_item;
vlc_mutex_init( p_obj, &p_res->input.lock ); vlc_mutex_init( p_obj, &p_res->input.lock );
p_res->input.ppsz_options = malloc( p_item->input.i_options * sizeof(char*));
if( p_item->input.i_options )
p_res->input.ppsz_options =
malloc( p_item->input.i_options * sizeof(char*) );
for( i = 0; i < p_item->input.i_options; i++ ) for( i = 0; i < p_item->input.i_options; i++ )
{ {
p_res->input.ppsz_options[i] = strdup( p_item->input.ppsz_options[i] ); p_res->input.ppsz_options[i] = strdup( p_item->input.ppsz_options[i] );
} }
if( p_item->i_children != -1 ) if( p_item->i_children != -1 )
{ {
msg_Warn( p_obj, "not copying playlist items children" ); msg_Warn( p_obj, "not copying playlist items children" );
...@@ -139,7 +143,8 @@ playlist_item_t *__playlist_ItemCopy( vlc_object_t *p_obj, ...@@ -139,7 +143,8 @@ playlist_item_t *__playlist_ItemCopy( vlc_object_t *p_obj,
if( p_item->input.i_es ) if( p_item->input.i_es )
{ {
p_res->input.es = (es_format_t**)malloc( p_item->input.i_es * sizeof(es_format_t*)); p_res->input.es =
(es_format_t**)malloc( p_item->input.i_es * sizeof(es_format_t*));
for( i = 0; i < p_item->input.i_es; i++ ) for( i = 0; i < p_item->input.i_es; i++ )
{ {
p_res->input.es[ i ] = (es_format_t*)malloc(sizeof(es_format_t*)); p_res->input.es[ i ] = (es_format_t*)malloc(sizeof(es_format_t*));
...@@ -329,6 +334,7 @@ int playlist_ItemSetName( playlist_item_t *p_item, char *psz_name ) ...@@ -329,6 +334,7 @@ int playlist_ItemSetName( playlist_item_t *p_item, char *psz_name )
{ {
if( psz_name && p_item ) if( psz_name && p_item )
{ {
if( p_item->input.psz_name ) free( p_item->input.psz_name );
p_item->input.psz_name = strdup( psz_name ); p_item->input.psz_name = strdup( psz_name );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
...@@ -120,7 +120,7 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent ) ...@@ -120,7 +120,7 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent )
p_playlist->i_size = 0; p_playlist->i_size = 0;
p_playlist->pp_items = NULL; p_playlist->pp_items = NULL;
p_playlist->i_all_size = 0; p_playlist->i_all_size = 0;
p_playlist->pp_all_items = malloc(sizeof(playlist_item_t*)); p_playlist->pp_all_items = 0;
playlist_ViewInsert( p_playlist, VIEW_CATEGORY, TITLE_CATEGORY ); playlist_ViewInsert( p_playlist, VIEW_CATEGORY, TITLE_CATEGORY );
playlist_ViewInsert( p_playlist, VIEW_SIMPLE, TITLE_SIMPLE ); playlist_ViewInsert( p_playlist, VIEW_SIMPLE, TITLE_SIMPLE );
...@@ -258,7 +258,6 @@ int playlist_LockControl( playlist_t * p_playlist, int i_query, ... ) ...@@ -258,7 +258,6 @@ int playlist_LockControl( playlist_t * p_playlist, int i_query, ... )
va_end( args ); va_end( args );
vlc_mutex_unlock( &p_playlist->object_lock ); vlc_mutex_unlock( &p_playlist->object_lock );
return i_result; return i_result;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment