]> git.sesse.net Git - vlc/commitdiff
* ALL: fixed a handful of bugs and memory leaks.
authorGildas Bazin <gbazin@videolan.org>
Tue, 12 Apr 2005 18:15:33 +0000 (18:15 +0000)
committerGildas Bazin <gbazin@videolan.org>
Tue, 12 Apr 2005 18:15:33 +0000 (18:15 +0000)
modules/demux/playlist/b4s.c
modules/misc/xml/xtag.c
src/input/stream.c
src/playlist/item.c
src/playlist/playlist.c

index 099341705c151e98fd032c694d98671abab9caaa..a32d4ab8277fb705ebf023691b8795b16ba33627 100644 (file)
@@ -154,7 +154,10 @@ static int Demux( demux_t *p_demux )
     p_xml = p_sys->p_xml = xml_Create( p_demux );
     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 );
     if( !p_xml_reader ) return -1;
     p_sys->p_xml_reader = p_xml_reader;
index bd0696d1daa9653178f5db55d4f1b378b31af89c..5f11e3ed3ce63392312f1e8e804c035a2608ef2d 100644 (file)
@@ -166,31 +166,22 @@ static xml_reader_t *ReaderCreate( xml_t *p_xml, stream_t *s )
 {
     xml_reader_t *p_reader;
     char *p_buffer;
-    int i_pos,i_size,i_buffer = 5000;
+    int i_size, i_pos = 0, i_buffer = 2048;
     XTag *p_root;
 
     /* Open and read file */
-    p_buffer = malloc( i_buffer + 1 );
-    if( p_buffer == NULL )
-        return NULL;
+    p_buffer = malloc( i_buffer );
+    if( p_buffer == NULL ) return NULL;
 
-    i_pos = 0;
-    i_size = 0;
-    while( i_pos < i_buffer )
+    while( ( i_size = stream_Read( s, &p_buffer[i_pos], 2048 ) ) == 2048 )
     {
-        i_size = stream_Read( s, &p_buffer[i_pos], 5000 );
         i_pos += i_size;
-        if( i_size < 5000 )
-            break; /* we're done */
-        else
-        {
-            i_buffer += 5000;
-            p_buffer = realloc( p_buffer, i_buffer * sizeof( char *) );
-        }
+        i_buffer += i_size;
+        p_buffer = realloc( p_buffer, i_buffer );
     }
-    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" );
         free( p_buffer );
index 6b68d99a97a43c827dfececd0f60cec01fd98e73..3db6a5a22d909d2c115f34c5250c5757e29a9f01 100644 (file)
@@ -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 )
 {
@@ -194,32 +194,29 @@ stream_t *__stream_UrlNew( vlc_object_t *p_parent, const char *psz_url )
     access_t *p_access;
     stream_t *p_res;
 
+    if( !psz_url ) return 0;
+
     psz_dup = strdup( psz_url );
     MRLSplit( p_parent, psz_dup, &psz_access, &psz_demux, &psz_path );
     
     /* Now try a real access */
-    p_access = access2_New( p_parent, psz_access, NULL,
-                            psz_path, VLC_FALSE );
+    p_access = access2_New( p_parent, psz_access, psz_demux, psz_path, 0 );
+    free( psz_dup );
 
     if( p_access == NULL )
     {
         msg_Err( p_parent, "no suitable access module for `%s'", psz_url );
-        free( psz_dup );
         return NULL;
     }
-    p_res = stream_AccessNew( p_access, VLC_TRUE );
-    if( p_res )
-    {
-        p_res->pf_destroy = UStreamDestroy;
-        free( psz_dup );
-        return p_res;
-    }
-    else
+
+    if( !( p_res = stream_AccessNew( p_access, VLC_TRUE ) ) )
     {
         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 )
index 3152bb6770a4e722128e62076699d40f71c3a7f1..3957f1c3932a30ddb67604d797bc8ece7850aae1 100644 (file)
@@ -116,13 +116,17 @@ playlist_item_t *__playlist_ItemCopy( vlc_object_t *p_obj,
         return NULL;
     }
 
-    memcpy( p_res, p_item, sizeof(playlist_item_t) );
+    *p_res = *p_item;
     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++ )
     {
         p_res->input.ppsz_options[i] = strdup( p_item->input.ppsz_options[i] );
     }
+
     if( p_item->i_children != -1 )
     {
         msg_Warn( p_obj, "not copying playlist items children" );
@@ -139,7 +143,8 @@ playlist_item_t *__playlist_ItemCopy( vlc_object_t *p_obj,
     
     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++ )
         {
             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 )
 {
     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 );
         return VLC_SUCCESS;
     }
index 48dfd70889fd72ed8154cea2fa04a30d90852501..0188a6e47d0f470650c6ef17fa0cb09fd491b5c0 100644 (file)
@@ -120,7 +120,7 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent )
     p_playlist->i_size = 0;
     p_playlist->pp_items = NULL;
     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_SIMPLE, TITLE_SIMPLE );
@@ -258,7 +258,6 @@ int playlist_LockControl( playlist_t * p_playlist, int i_query, ... )
     va_end( args );
     vlc_mutex_unlock( &p_playlist->object_lock );
     return i_result;
-    
 }
 
 /**