From 38dbd37adf32cf04e1caf17ceb7888a4a5ec2f40 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C3=ABl=20Carr=C3=A9?= Date: Sat, 18 Aug 2007 03:22:03 +0000 Subject: [PATCH] Input access locking. Part one --- include/vlc_input.h | 20 +++++++- modules/control/dbus.c | 3 +- modules/demux/flac.c | 3 +- modules/gui/macosx/playlist.m | 54 ++++++++++++-------- modules/gui/qt4/components/infopanels.cpp | 12 +++-- modules/gui/qt4/input_manager.cpp | 20 ++++---- modules/gui/qt4/playlist_model.cpp | 24 ++++++--- modules/gui/wxwidgets/dialogs/infopanels.cpp | 5 +- modules/gui/wxwidgets/dialogs/playlist.cpp | 4 +- modules/gui/wxwidgets/input_manager.cpp | 3 +- modules/gui/wxwidgets/playlist_manager.cpp | 3 +- modules/meta_engine/luameta.c | 25 ++++++--- modules/meta_engine/musicbrainz.c | 17 ++++-- modules/meta_engine/taglib.cpp | 33 ++++++++---- modules/misc/audioscrobbler.c | 23 ++++++--- src/control/media_descriptor.c | 12 +++-- src/playlist/search.c | 25 +++++++-- src/playlist/sort.c | 6 ++- 18 files changed, 201 insertions(+), 91 deletions(-) diff --git a/include/vlc_input.h b/include/vlc_input.h index 597c9f805a..12aaa91d0d 100644 --- a/include/vlc_input.h +++ b/include/vlc_input.h @@ -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 ) diff --git a/modules/control/dbus.c b/modules/control/dbus.c index 2f3a8934cc..075010d93a 100644 --- a/modules/control/dbus.c +++ b/modules/control/dbus.c @@ -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, diff --git a/modules/demux/flac.c b/modules/demux/flac.c index 831b1260e6..c57d72027d 100644 --- a/modules/demux/flac.c +++ b/modules/demux/flac.c @@ -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 ) diff --git a/modules/gui/macosx/playlist.m b/modules/gui/macosx/playlist.m index cadeb91fc3..85cff49418 100644 --- a/modules/gui/macosx/playlist.m +++ b/modules/gui/macosx/playlist.m @@ -271,38 +271,50 @@ 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 ); diff --git a/modules/gui/qt4/components/infopanels.cpp b/modules/gui/qt4/components/infopanels.cpp index ab75422e94..ea98b34208 100644 --- a/modules/gui/qt4/components/infopanels.cpp +++ b/modules/gui/qt4/components/infopanels.cpp @@ -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 ); } /* diff --git a/modules/gui/qt4/input_manager.cpp b/modules/gui/qt4/input_manager.cpp index c8c18eb8b1..a1a58592f5 100644 --- a/modules/gui/qt4/input_manager.cpp +++ b/modules/gui/qt4/input_manager.cpp @@ -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 ); diff --git a/modules/gui/qt4/playlist_model.cpp b/modules/gui/qt4/playlist_model.cpp index aadab0e07d..839e4a2a08 100644 --- a/modules/gui/qt4/playlist_model.cpp +++ b/modules/gui/qt4/playlist_model.cpp @@ -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 #include @@ -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 ); diff --git a/modules/gui/wxwidgets/dialogs/infopanels.cpp b/modules/gui/wxwidgets/dialogs/infopanels.cpp index 20d6f6c94e..c2b04f28c0 100644 --- a/modules/gui/wxwidgets/dialogs/infopanels.cpp +++ b/modules/gui/wxwidgets/dialogs/infopanels.cpp @@ -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 ); diff --git a/modules/gui/wxwidgets/dialogs/playlist.cpp b/modules/gui/wxwidgets/dialogs/playlist.cpp index 4f91dc6fc8..5d384caa35 100644 --- a/modules/gui/wxwidgets/dialogs/playlist.cpp +++ b/modules/gui/wxwidgets/dialogs/playlist.cpp @@ -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; diff --git a/modules/gui/wxwidgets/input_manager.cpp b/modules/gui/wxwidgets/input_manager.cpp index 2add7473e1..d052895be1 100644 --- a/modules/gui/wxwidgets/input_manager.cpp +++ b/modules/gui/wxwidgets/input_manager.cpp @@ -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 ) diff --git a/modules/gui/wxwidgets/playlist_manager.cpp b/modules/gui/wxwidgets/playlist_manager.cpp index dd5cc7e34c..9e467e488c 100644 --- a/modules/gui/wxwidgets/playlist_manager.cpp +++ b/modules/gui/wxwidgets/playlist_manager.cpp @@ -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 ); diff --git a/modules/meta_engine/luameta.c b/modules/meta_engine/luameta.c index 8292912b4e..10f16693b5 100644 --- a/modules/meta_engine/luameta.c +++ b/modules/meta_engine/luameta.c @@ -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; } diff --git a/modules/meta_engine/musicbrainz.c b/modules/meta_engine/musicbrainz.c index 6a6c150e6b..c3ee1df99f 100644 --- a/modules/meta_engine/musicbrainz.c +++ b/modules/meta_engine/musicbrainz.c @@ -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 ) diff --git a/modules/meta_engine/taglib.cpp b/modules/meta_engine/taglib.cpp index 4364ce487e..c0b8827a15 100644 --- a/modules/meta_engine/taglib.cpp +++ b/modules/meta_engine/taglib.cpp @@ -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; diff --git a/modules/misc/audioscrobbler.c b/modules/misc/audioscrobbler.c index 7a9b3c63d9..8ea6feb34c 100644 --- a/modules/misc/audioscrobbler.c +++ b/modules/misc/audioscrobbler.c @@ -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 { diff --git a/src/control/media_descriptor.c b/src/control/media_descriptor.c index 02f58ace97..95bc72c6ea 100644 --- a/src/control/media_descriptor.c +++ b/src/control/media_descriptor.c @@ -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; } diff --git a/src/playlist/search.c b/src/playlist/search.c index e7e6916754..15c29f6039 100644 --- a/src/playlist/search.c +++ b/src/playlist/search.c @@ -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; diff --git a/src/playlist/sort.c b/src/playlist/sort.c index 9eab21f2f6..9943e03f94 100644 --- a/src/playlist/sort.c +++ b/src/playlist/sort.c @@ -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; } -- 2.39.5