]> git.sesse.net Git - vlc/commitdiff
Input access locking. Part one
authorRafaël Carré <funman@videolan.org>
Sat, 18 Aug 2007 03:22:03 +0000 (03:22 +0000)
committerRafaël Carré <funman@videolan.org>
Sat, 18 Aug 2007 03:22:03 +0000 (03:22 +0000)
18 files changed:
include/vlc_input.h
modules/control/dbus.c
modules/demux/flac.c
modules/gui/macosx/playlist.m
modules/gui/qt4/components/infopanels.cpp
modules/gui/qt4/input_manager.cpp
modules/gui/qt4/playlist_model.cpp
modules/gui/wxwidgets/dialogs/infopanels.cpp
modules/gui/wxwidgets/dialogs/playlist.cpp
modules/gui/wxwidgets/input_manager.cpp
modules/gui/wxwidgets/playlist_manager.cpp
modules/meta_engine/luameta.c
modules/meta_engine/musicbrainz.c
modules/meta_engine/taglib.cpp
modules/misc/audioscrobbler.c
src/control/media_descriptor.c
src/playlist/search.c
src/playlist/sort.c

index 597c9f805a885f01af636a1b66c87c98f8b90598..12aaa91d0d754fb60b49eb9445a17125104e06de 100644 (file)
@@ -221,9 +221,11 @@ static inline void input_ItemClean( input_item_t *p_i )
 static inline void input_item_SetMeta( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz_val )
 {
     vlc_event_t event;
+    vlc_mutex_lock( &p_i->p_lock );
     if( !p_i->p_meta )
         p_i->p_meta = vlc_meta_New();
     vlc_meta_Set( p_i->p_meta, meta_type, psz_val );
+    vlc_mutex_unlock( &p_i->p_lock ); 
 
     /* Notify interested third parties */
     event.type = vlc_InputItemMetaChanged;
@@ -231,11 +233,25 @@ static inline void input_item_SetMeta( input_item_t *p_i, vlc_meta_type_t meta_t
     vlc_event_send( &p_i->event_manager, &event );
 }
 
-static inline const char * input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type )
+static inline char * input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type )
 {
+    vlc_mutex_lock( &p_i->p_lock );
     if( !p_i->p_meta )
+    {
+        vlc_mutex_unlock( &p_i->p_lock );
         return NULL;
-    return vlc_meta_Get( p_i->p_meta, meta_type );
+    }
+    char *psz_s = strdup( vlc_meta_Get( p_i->p_meta, meta_type ) );
+    vlc_mutex_unlock( &p_i->p_lock );
+    return psz_s;
+}
+
+static inline char * input_item_GetName( input_item_t *p_i )
+{
+    vlc_mutex_lock( &p_i->p_lock );
+    char *psz_s = strdup( p_i->psz_name );
+    vlc_mutex_unlock( &p_i->p_lock );
+    return psz_s;
 }
 
 static inline void input_item_SetPreparsed( input_item_t *p_i, vlc_bool_t preparsed )
index 2f3a8934ccf5f06a8674a83c29141a66460b4662..075010d93a432d7a5807d56ebdb70eb1969a7d14 100644 (file)
@@ -866,9 +866,10 @@ static int TrackChange( vlc_object_t *p_this, const char *psz_var,
 
 #define ADD_VLC_META_STRING( entry, item ) \
     { \
-        const char * psz = input_item_Get##item( p_input );\
+        char * psz = input_item_Get##item( p_input );\
         ADD_META( entry, DBUS_TYPE_STRING, \
                   psz ); \
+        free( psz ); \
     }
 
 static int GetInputMeta( input_item_t* p_input,
index 831b1260e63c90634a1190d70062e6ca00cfa488..c57d72027d560a3a1ca73167d5893497d6e48b0b 100644 (file)
@@ -620,7 +620,7 @@ static void ParseComment( demux_t *p_demux, const uint8_t *p_data, int i_data )
 #define IF_EXTRACT(txt,var) \
     if( !strncasecmp(psz, txt, strlen(txt)) ) \
     { \
-        const char * oldval = vlc_meta_Get( p_sys->p_meta, vlc_meta_ ## var ); \
+        char * oldval = vlc_meta_Get( p_sys->p_meta, vlc_meta_ ## var ); \
         if( oldval ) \
         { \
             char * newval; \
@@ -630,6 +630,7 @@ static void ParseComment( demux_t *p_demux, const uint8_t *p_data, int i_data )
         } \
         else \
             vlc_meta_Set( p_sys->p_meta, vlc_meta_ ## var, &psz[strlen(txt)] ); \
+        free( oldval ); \
     }
         IF_EXTRACT("TITLE=", Title )
         else IF_EXTRACT("ALBUM=", Album )
index cadeb91fc3bf6f19ce44973ecc68f0f4d0fec4a2..85cff494182f6cd3e510a4b47de919972fbbc78d 100644 (file)
     if( [[o_tc identifier] isEqualToString:@"1"] )
     {
         /* sanity check to prevent the NSString class from crashing */
-        if( !EMPTY_STR( input_item_GetTitle( p_item->p_input ) ) )
+        char *psz_title =  input_item_GetTitle( p_item->p_input );
+        if( !EMPTY_STR( psz_title ) ) )
         {
-            o_value = [NSString stringWithUTF8String: input_item_GetTitle( p_item->p_input )];
+            o_value = [NSString stringWithUTF8String: psz_title )];
             if( o_value == NULL )
-                o_value = [NSString stringWithCString: input_item_GetTitle( p_item->p_input )];
+                o_value = [NSString stringWithCString: psz_title )];
         } 
-        else if( p_item->p_input->psz_name != NULL )
+        else
         {
-            o_value = [NSString stringWithUTF8String: p_item->p_input->psz_name];
-            if( o_value == NULL )
-                o_value = [NSString stringWithCString: p_item->p_input->psz_name];
+            char *psz_name = input_item_GetName( p_item->p_input );
+            if( psz_name != NULL )
+            {
+                o_value = [NSString stringWithUTF8String: psz_name];
+                if( o_value == NULL )
+                    o_value = [NSString stringWithCString: psz_name];
+            }
         }
+        free( psz_title );
+        free( psz_name );
     }
-    else if( [[o_tc identifier] isEqualToString:@"2"] && !EMPTY_STR( input_item_GetArtist( p_item->p_input ) ) )
-    {
-        o_value = [NSString stringWithUTF8String: input_item_GetArtist( p_item->p_input )];
-        if( o_value == NULL )
-            o_value = [NSString stringWithCString: input_item_GetArtist( p_item->p_input )];
-    }
-    else if( [[o_tc identifier] isEqualToString:@"3"] )
+    else
     {
-        char psz_duration[MSTRTIME_MAX_SIZE];
-        mtime_t dur = p_item->p_input->i_duration;
-        if( dur != -1 )
+        char *psz_artist = input_item_GetArtist( p_item->p_input );
+        if( [[o_tc identifier] isEqualToString:@"2"] && !EMPTY_STR( psz_artist ) )
         {
-            secstotimestr( psz_duration, dur/1000000 );
-            o_value = [NSString stringWithUTF8String: psz_duration];
+            o_value = [NSString stringWithUTF8String: psz_artist )];
+            if( o_value == NULL )
+                o_value = [NSString stringWithCString: psz_artist )];
         }
-        else
+        else if( [[o_tc identifier] isEqualToString:@"3"] )
         {
-            o_value = @"-:--:--";
+            char psz_duration[MSTRTIME_MAX_SIZE];
+            mtime_t dur = p_item->p_input->i_duration;
+            if( dur != -1 )
+            {
+                secstotimestr( psz_duration, dur/1000000 );
+                o_value = [NSString stringWithUTF8String: psz_duration];
+            }
+            else
+            {
+                o_value = @"-:--:--";
+            }
         }
+        free( psz_artist );
     }
 
     return( o_value );
index ab75422e9441a75830539ee6940ea63fc0fbc864..ea98b3420835ef6aca217d9eed688bed52979761 100644 (file)
@@ -188,18 +188,21 @@ void MetaPanel::saveMeta()
  **/
 void MetaPanel::update( input_item_t *p_item )
 {
-    const char *psz_meta; 
+    char *psz_meta; 
 #define UPDATE_META( meta, widget ) {               \
     psz_meta = input_item_Get##meta( p_item );      \
     if( !EMPTY_STR( psz_meta ) )                    \
         widget->setText( qfu( psz_meta ) );         \
     else                                            \
-        widget->setText( "" ); }
+        widget->setText( "" ); }                    \
+    free( psz_meta );
 
 #define UPDATE_META_INT( meta, widget ) {           \
     psz_meta = input_item_Get##meta( p_item );      \
     if( !EMPTY_STR( psz_meta ) )                    \
-        widget->setValue( atoi( psz_meta ) ); }
+        widget->setValue( atoi( psz_meta ) ); }     \
+    free( psz_meta );
+
 
     /* Name / Title */
     psz_meta = input_item_GetTitle( p_item );
@@ -208,6 +211,7 @@ void MetaPanel::update( input_item_t *p_item )
     else if( !EMPTY_STR( p_item->psz_name ) )
         title_text->setText( qfu( p_item->psz_name ) );
     else title_text->setText( "" );
+    free( psz_meta );
 
     /* URL / URI */
     psz_meta = input_item_GetURL( p_item );
@@ -215,6 +219,7 @@ void MetaPanel::update( input_item_t *p_item )
         emit uriSet( QString( psz_meta ) );
     else if( !EMPTY_STR( p_item->psz_uri ) )
         emit uriSet( QString( p_item->psz_uri ) );
+    free( psz_meta );
 
     /* Other classic though */
     UPDATE_META( Artist, artist_text );
@@ -243,6 +248,7 @@ void MetaPanel::update( input_item_t *p_item )
     }
     else
         art_cover->setPixmap( QPixmap( ":/noart.png" ) );
+    free( psz_meta );
 }
 
 /*
index c8c18eb8b1a41ed6b94b383f85717231cc0534d0..a1a58592f52c71fcec48e7d327974fc518075656 100644 (file)
@@ -132,22 +132,24 @@ void InputManager::update()
 
     /* Update text */
     QString text;
-    if( !EMPTY_STR(input_item_GetNowPlaying( input_GetItem(p_input) )) )
+    char *psz_name = input_GetName( input_GetItem( p_input ) );
+    char *psz_nowplaying = input_item_GetNowPlaying( input_GetItem( p_input );
+    char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
+    if( !EMPTY_STR( psz_nowplaying ) )
     {
-        text.sprintf( "%s - %s",
-                  input_item_GetNowPlaying( input_GetItem(p_input) ),
-                  input_GetItem(p_input)->psz_name );
+        text.sprintf( "%s - %s", psz_now_playing, psz_name );
     }
-    else if( !EMPTY_STR(input_item_GetArtist( input_GetItem(p_input) )) )
+    else if( !EMPTY_STR( psz_artist ) )
     {
-        text.sprintf( "%s - %s",
-                  input_item_GetArtist( input_GetItem(p_input) ),
-                  input_GetItem(p_input)->psz_name );
+        text.sprintf( "%s - %s", psz_artist, psz_name );
     }
     else
     {
-        text.sprintf( "%s", input_GetItem(p_input)->psz_name );
+        text.sprintf( "%s", psz_name );
     }
+    free( psz_name );
+    free( psz_nowplaying );
+    free( psz_artist );
     if( old_name != text )
     {
         emit nameChanged( text );
index aadab0e07d8ab221dc7e2f486e828ebd4fb97e16..839e4a2a08c8402b0777a947ec9a69dbb1a56914 100644 (file)
@@ -20,7 +20,6 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
-#define PLI_NAME( p ) p ? p->p_input->psz_name : "null"
 
 #include <assert.h>
 #include <QIcon>
@@ -184,11 +183,13 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
     type = p_item->p_input->i_type;
     current = iscurrent;
 
-    if( current && input_item_GetArtURL( p_item->p_input ) &&
-        !strncmp( input_item_GetArtURL( p_item->p_input ), "file://", 7 ) )
-        model->sendArt( qfu( input_item_GetArtURL( p_item->p_input ) ) );
+    char *psz_arturl = input_item_GetArtURL( p_item->p_input );
+    if( current && psz_arturl ) &&
+        !strncmp( psz_arturl, "file://", 7 ) )
+        model->sendArt( qfu( psz_arturl ) ) );
     else if( current )
         model->removeArt();
+    free( psz_arturl );
 
     strings.clear();
 
@@ -198,9 +199,11 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
         return;
     }
 
-
+    char *psz_meta;
 #define ADD_META( item, meta ) \
-      strings.append( qfu( input_item_Get ## meta ( item->p_input ) ) )
+      psz_meta = input_item_Get ## meta ( item->p_input ); \
+      strings.append( qfu( psz_meta ) ); \
+      free( psz_meta );
 
     for( int i_index=1; i_index <= VLC_META_ENGINE_MB_TRM_ID; i_index = i_index * 2 )
     {
@@ -212,12 +215,17 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
                     ADD_META( p_item, Artist );
                     break;
                 case VLC_META_ENGINE_TITLE:
-                    if( input_item_GetTitle( p_item->p_input ) )
+                    char *psz_title;
+                    psz_title = input_item_GetTile( p_item->p_input );
+                    psz_name = input_item_GetName( p_item->p_input );
+                    if( psz_title )
                     {
                         ADD_META( p_item, Title );
                     } else {
-                        strings.append( qfu( p_item->p_input->psz_name ) );
+                        strings.append( qfu( psz_name ) );
                     }
+                    free( psz_title );
+                    free( psz_name );
                     break;
                 case VLC_META_ENGINE_DESCRIPTION:
                     ADD_META( p_item, Description );
index 20d6f6c94e27c4f504c6a9026ab724f55c542bac..c2b04f28c064bdec8162d9426d5f139a9093e145 100644 (file)
@@ -121,13 +121,14 @@ void MetaDataPanel::Update( input_item_t *p_item )
     name_text->SetValue( wxU( p_item->psz_name ) );
 
 #define UPDATE_META( meta, widget ) {                                       \
-    const char *psz_meta = input_item_Get##meta( p_item );                  \
+    char *psz_meta = input_item_Get##meta( p_item );                        \
     if( psz_meta != NULL && *psz_meta)                                      \
     {                                                                       \
         widget->SetLabel( wxU( psz_meta ) );                                \
     }                                                                       \
     else { widget->SetLabel( wxU( "-" ) ); }                                \
-    }
+    }                                                                       \
+    free( psz_meta );
 
     UPDATE_META( Artist, artist_text );
     UPDATE_META( Genre, genre_text );
index 4f91dc6fc8301ddeaff6b8d10e1da6db66f1b269..5d384caa35dee98fa7ac7f7f53426eaac9e82cc6 100644 (file)
@@ -513,9 +513,7 @@ void Playlist::UpdateTreeItem( wxTreeItemId item )
     wxString duration = wxU( "" );
 
     char *psz_artist;
-    psz_artist = input_item_GetArtist( p_item->p_input ) ?
-                    strdup( input_item_GetArtist( p_item->p_input ) ) :
-                    strdup("");
+    psz_artist = input_item_GetArtist( p_item->p_input );
 
     char psz_duration[MSTRTIME_MAX_SIZE];
     mtime_t dur = p_item->p_input->i_duration;
index 2add7473e10a9bd194ef383cfeaf1f0df8ac27f1..d052895be10823a53e3610d63308a0896fe97f79 100644 (file)
@@ -210,7 +210,7 @@ void InputManager::UpdateInput()
 
 void InputManager::UpdateNowPlaying()
 {
-    const char *psz_now_playing = input_item_GetNowPlaying( input_GetItem(p_input) );
+    char *psz_now_playing = input_item_GetNowPlaying( input_GetItem(p_input) );
     if( psz_now_playing && *psz_now_playing )
     {
         p_main_intf->statusbar->SetStatusText(
@@ -222,6 +222,7 @@ void InputManager::UpdateNowPlaying()
         p_main_intf->statusbar->SetStatusText(
                    wxU(input_GetItem(p_input)->psz_name), 2 );
     }
+    free( psz_now_playing );
 }
 
 void InputManager::UpdateButtons( vlc_bool_t b_play )
index dd5cc7e34cedc3fdad37fb422450fc678f78db90..9e467e488cd63692d45fe65c0e8847398e6f2cad 100644 (file)
@@ -299,7 +299,7 @@ void PlaylistManager::UpdateTreeItem( wxTreeItemId item )
     wxString msg;
     wxString duration = wxU( "" );
 
-    const char *psz_artist = input_item_GetArtist( p_item->p_input );
+    char *psz_artist = input_item_GetArtist( p_item->p_input );
     if( ! psz_artist )
     {
         psz_artist = "";
@@ -324,6 +324,7 @@ void PlaylistManager::UpdateTreeItem( wxTreeItemId item )
         msg = wxString(wxU( psz_artist )) + wxT(" - ") +
                     wxString(wxU(p_item->p_input->psz_name)) + duration;
     }
+    free( psz_artist );
     treectrl->SetItemText( item , msg );
     treectrl->SetItemImage( item, p_item->p_input->i_type );
 
index 8292912b4e583fe6d3a51279c07b65535b8f8b82..10f16693b51e446f7d15ae83b203b61ced0a1a64 100644 (file)
@@ -250,6 +250,7 @@ static lua_State * vlclua_meta_init( vlc_object_t *p_this, input_item_t * p_item
         msg_Err( p_this, "Could not create new Lua State" );
         return NULL;
     }
+    char *psz_meta;
 
     /* Load Lua libraries */
     luaL_openlibs( p_state ); /* XXX: Don't open all the libs? */
@@ -258,19 +259,27 @@ static lua_State * vlclua_meta_init( vlc_object_t *p_this, input_item_t * p_item
     
     lua_pushlightuserdata( p_state, p_this );
     lua_setfield( p_state, lua_gettop( p_state ) - 1, "private" );
-    
-    lua_pushstring( p_state, p_item->psz_name );
+   
+    psz_meta = input_item_GetName( p_item );
+    lua_pushstring( p_state, psz_meta );
     lua_setfield( p_state, lua_gettop( p_state ) - 1, "name" );
-    
-    lua_pushstring( p_state, input_item_GetTitle( p_item ) );
+    free( psz_meta );
+   
+    psz_meta = input_item_GetTitle( p_item ) ;
+    lua_pushstring( p_state, psz_meta );
     lua_setfield( p_state, lua_gettop( p_state ) - 1, "title" );
-    
-    lua_pushstring( p_state, input_item_GetAlbum( p_item ) );
+    free( psz_meta );
+   
+    psz_meta = input_item_GetAlbum( p_item );
+    lua_pushstring( p_state, psz_meta );
     lua_setfield( p_state, lua_gettop( p_state ) - 1, "album" );
+    free( psz_meta );
 
-    lua_pushstring( p_state, input_item_GetArtURL( p_item ) );
+    psz_meta = input_item_GetArtURL( p_item );
+    lua_pushstring( p_state, psz_meta );
     lua_setfield( p_state, lua_gettop( p_state ) - 1, "arturl" );
-    /* XXX: all should be passed */
+    free( psz_meta );
+    /* XXX: all should be passed ( could use macro ) */
 
     return p_state;
 }
index 6a6c150e6b6fa0d3229d76160d7013fc85c7a65e..c3ee1df99f23fe60ba022e9345419b4415f468eb 100644 (file)
@@ -77,16 +77,20 @@ static int GetData( vlc_object_t *p_obj, input_item_t *p_item,
     char i_album_count, i;
     char *ppsz_args[4];
 
-    char *psz_title;
     char *psz_artist;
     char *psz_album;
 
     psz_artist = input_item_GetArtist( p_item );
     psz_album = input_item_GetAlbum( p_item );
-    psz_title = p_item->psz_name;
 
     if( !psz_artist || !psz_album )
+    {
+        free( psz_artist );
+        free( psz_album );
         return VLC_EGENERIC;
+    }
+    free( psz_artist );
+    free( psz_album );
 
     musicbrainz_t p_mb;
 
@@ -154,8 +158,13 @@ static int GetData( vlc_object_t *p_obj, input_item_t *p_item,
     if( !b_art )
         return VLC_SUCCESS;
     else
-        return EMPTY_STR( input_item_GetArtURL( p_item ) ) ?
-               VLC_SUCCESS : VLC_EGENERIC;
+    {
+        char *psz_arturl;
+        psz_arturl = input_item_GetArtURL( p_item );
+        int i_ret;
+        i_ret = EMPTY_STR( psz_arturl ) ? VLC_SUCCESS : VLC_EGENERIC ;
+        free( psz_arturl );
+        return i_ret;
 }
 
 static int FindMetaMBId( vlc_object_t *p_this )
index 4364ce487efe9f58d24a64cde04753622e39ef2d..c0b8827a15d2f680a677b4184919e40f97f8e7c5 100644 (file)
@@ -193,22 +193,35 @@ static int WriteMeta( vlc_object_t *p_this )
 
         TagLib::Tag *tag = f.tag();
 
-        SET( Artist, input_item_GetArtist( p_item ) );
+        char *psz_meta;
 
-        const char *psz_titlec = ( input_item_GetTitle( p_item ) ?
-            input_item_GetTitle( p_item ) : p_item->psz_name );
-        TagLib::String *psz_title = new TagLib::String( psz_titlec,
+        psz_meta = input_item_GetArtist( p_item );
+        SET( Artist, psz_meta );
+        free( psz_meta );
+
+        psz_meta = input_item_GetTitle( p_item );
+        if( !psz_meta ) psz_meta = input_item_GetName( p_item );
+        TagLib::String *psz_title = new TagLib::String( psz_meta,
             TagLib::String::UTF8 );
         tag->setTitle( *psz_title );
         delete psz_title;
+        free( psz_meta );
+
+        psz_meta = input_item_GetAlbum( p_item );
+        SET( Album, psz_meta );
+        free( psz_meta );
+
+        psz_meta = input_item_GetGenre( p_item );
+        SET( Genre, psz_meta );
+        free( psz_meta );
 
-        SET( Album, input_item_GetAlbum( p_item ) );
-        SET( Genre, input_item_GetGenre( p_item ) );
+        psz_meta = input_item_GetDate( p_item );
+        if( psz_meta ) tag->setYear( atoi( psz_meta ) );
+        free( psz_meta );
 
-        if( input_item_GetDate( p_item ) )
-            tag->setYear( atoi( input_item_GetDate( p_item ) ) );
-        if( input_item_GetTrackNum( p_item ) )
-            tag->setTrack( atoi( input_item_GetTrackNum( p_item ) ) );
+        psz_meta = input_item_GetTrackNum( p_item );
+        if( psz_meta ) tag->setTrack( atoi( psz_meta ) );
+        free( psz_meta );
 
         f.save();
         return VLC_SUCCESS;
index 7a9b3c63d921ce1ab81f9f716f5e02d3cffa5d20..8ea6feb34c4064eff3196c99504c1d9fdabc4901 100644 (file)
@@ -630,8 +630,10 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     p_sys->p_current_song->psz_i = encode_URI_component( psz_date );
     p_sys->p_current_song->time_playing = epoch;
 
-    p_sys->b_paused = ( p_input->b_dead || !input_GetItem(p_input)->psz_name )
+    char *psz_name = input_item_GetName( input_GetItem( p_input ) );
+    p_sys->b_paused = ( p_input->b_dead || !psz_name )
                       ? VLC_TRUE : VLC_FALSE;
+    free( psz_name );
 
     vlc_mutex_unlock( &p_sys->lock );
 
@@ -1003,7 +1005,7 @@ static int ReadMetaData( intf_thread_t *p_this )
 
     var_Change( p_input, "video-es", VLC_VAR_CHOICESCOUNT, &video_val, NULL );
     if( ( video_val.i_int > 0 ) || \
-        ( input_GetItem(p_input)->i_type == ITEM_TYPE_NET ) )
+        ( input_GetItem( p_input )->i_type == ITEM_TYPE_NET ) )
     {
         msg_Dbg( p_this, "Not an audio only local file -> no submission");
         vlc_object_release( p_input );
@@ -1038,16 +1040,19 @@ static int ReadMetaData( intf_thread_t *p_this )
             return VLC_SUCCESS; \
         }
 
+    char *psz_meta;
     #define ALLOC_ITEM_META( a, b ) \
-        if ( input_item_Get##b( input_GetItem(p_input) ) ) \
+        psz_meta = input_item_Get##b( input_GetItem( p_input ) ) \
+        if( psz_meta ) \
         { \
-            a = encode_URI_component( \
-                input_item_Get##b( input_GetItem(p_input) )); \
+            a = encode_URI_component( psz_meta ); \
             if( !a ) \
             { \
+                free( psz_meta ); \
                 FREE_INPUT_AND_CHARS \
                 return VLC_ENOMEM; \
             } \
+            free( psz_meta ); \
         }
 
     i_status = input_GetItem(p_input)->p_meta->i_status;
@@ -1064,15 +1069,17 @@ static int ReadMetaData( intf_thread_t *p_this )
             msg_Dbg( p_this, "No artist.." );
             WAIT_METADATA_FETCHING( psz_artist )
         }
-
-        if( input_GetItem(p_input)->psz_name )
+        psz_meta = input_item_GetName( input_GetItem( p_input ) );
+        if( psz_meta )
         {
-            psz_title = encode_URI_component( input_GetItem(p_input)->psz_name );
+            psz_title = encode_URI_component( psz_meta );
             if( !psz_title )
             {
+                free( psz_meta );
                 FREE_INPUT_AND_CHARS
                 return VLC_ENOMEM;
             }
+            free( psz_meta );
         }
         else
         {
index 02f58ace97fc45365b1e9d9c7af8057417f0b6d6..95bc72c6ea5468339374d747a7cd798af0d05d81 100644 (file)
@@ -276,7 +276,7 @@ char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_md,
                                          libvlc_meta_t e_meta,
                                          libvlc_exception_t *p_e )
 {
-    const char * psz_meta;
+    char * psz_meta;
 
     /* XXX: locking */
 
@@ -287,11 +287,17 @@ char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_md,
 
     /* Should be integrated in core */
     if( !psz_meta && e_meta == libvlc_meta_Title && p_md->p_input_item->psz_name )
+    {
+        free( psz_meta );
         return strdup( p_md->p_input_item->psz_name );
+    }
 
     if( !psz_meta )
-        return NULL;
+    {
+        free( psz_meta );
+        return NULL
+    }
 
-    return strdup( psz_meta );
+    return psz_meta;
 }
 
index e7e691675438ffa24b7c200763ccf011361ce09f..15c29f603965255e48959aefbbd17f054bfcc7f5 100644 (file)
@@ -120,12 +120,29 @@ int playlist_LiveSearchUpdate( playlist_t *p_playlist, playlist_item_t *p_root,
         {
             playlist_LiveSearchUpdate( p_playlist, p_item, psz_string );
         }
-#define META_MATCHES( field ) ( input_item_GetMeta( p_item->p_input, vlc_meta_##field ) && \
-                                strcasestr( input_item_GetMeta( p_item->p_input, vlc_meta_##field ), psz_string ) )
         else
         {
-            if( strcasestr( p_item->p_input->psz_name, psz_string ) ||
-                META_MATCHES( Artist ) || META_MATCHES( Album ) )
+            char *psz_name_matches, *psz_artist_matches, *psz_album_matches;
+            char *psz_field, *psz_field_case;
+
+            psz_field = input_item_GetName( p_i );
+            psz_name_matches = strcasestr( psz_field, psz_string );
+            free( psz_field );
+
+            psz_field = input_item_GetMeta( p_item->p_input, vlc_meta_Artist );
+            psz_field_case = strcasestr( input_item_GetMeta( p_item->p_input, vlc_meta_Artist ), psz_string );
+            psz_artist_matches = ( psz_field && psz_field_case );
+            free( psz_field );
+            free( psz_field_case );
+
+
+            psz_field = input_item_GetMeta( p_item->p_input, vlc_meta_Album );
+            psz_field_case = strcasestr( input_item_GetMeta( p_item->p_input, vlc_meta_Album ), psz_string );
+            psz_album_matches = ( psz_field && psz_field_case );
+            free( psz_field );
+            free( psz_field_case );
+
+            if( psz_name_matches || psz_artist_matches || psz_album_matches )
                 p_item->i_flags &= ~PLAYLIST_DBL_FLAG;
             else
                 p_item->i_flags |= PLAYLIST_DBL_FLAG;
index 9eab21f2f636efee513c2c2f488619b58b1a93fd..9943e03f942a4641de318a4388c93296039bbe96 100644 (file)
@@ -105,8 +105,8 @@ static int playlist_ItemArraySort( playlist_t *p_playlist, int i_items,
     }
 
 #define DO_META_SORT( node ) { \
-    const char *psz_a = input_item_GetMeta( pp_items[i]->p_input, vlc_meta_##node ); \
-    const char *psz_b = input_item_GetMeta( pp_items[i_small]->p_input, vlc_meta_##node ); \
+    char *psz_a = input_item_GetMeta( pp_items[i]->p_input, vlc_meta_##node ); \
+    char *psz_b = input_item_GetMeta( pp_items[i_small]->p_input, vlc_meta_##node ); \
     /* Nodes go first */ \
     if( pp_items[i]->i_children == -1 && pp_items[i_small]->i_children >= 0 ) \
         i_test = 1;\
@@ -198,5 +198,7 @@ static int playlist_ItemArraySort( playlist_t *p_playlist, int i_items,
         pp_items[i_position] = pp_items[i_small];
         pp_items[i_small] = p_temp;
     }
+    free( psz_a );
+    free( psz_b );
     return VLC_SUCCESS;
 }