p_dict->i_size = i_size;
}
-static inline void vlc_dictionary_clear( vlc_dictionary_t * p_dict )
+static inline void vlc_dictionary_clear( vlc_dictionary_t * p_dict,
+ void ( * pf_free )( void * p_data, void * p_obj ),
+ void * p_obj )
{
int i;
struct vlc_dictionary_entry_t * p_current, * p_next;
while( p_current )
{
p_next = p_current->p_next;
+ if( pf_free != NULL )
+ ( * pf_free )( p_current->p_value, p_obj );
free( p_current->psz_key );
free( p_current );
p_current = p_next;
}
}
- vlc_dictionary_clear( p_dict );
+ vlc_dictionary_clear( p_dict, NULL, NULL );
p_dict->i_size = new_dict.i_size;
p_dict->p_entries = new_dict.p_entries;
}
}
static inline void
-vlc_dictionary_remove_value_for_key( const vlc_dictionary_t * p_dict, const char * psz_key )
+vlc_dictionary_remove_value_for_key( const vlc_dictionary_t * p_dict, const char * psz_key,
+ void ( * pf_free )( void * p_data, void * p_obj ),
+ void * p_obj )
{
if( !p_dict->p_entries )
return;
do {
if( !strcmp( psz_key, p_entry->psz_key ) )
{
+ if( pf_free != NULL )
+ ( * pf_free )( p_entry->p_value, p_obj );
if( !p_prev )
p_dict->p_entries[i_pos] = p_entry->p_next;
else
#define vlc_meta_SetArtURL( meta, b ) vlc_meta_Set( meta, vlc_meta_ArtworkURL, b )
#define vlc_meta_SetTrackID( meta, b ) vlc_meta_Set( meta, vlc_meta_TrackID, b )
+/* Free a dictonary key allocated by strdup() in vlc_meta_AddExtra() */
+static void vlc_meta_FreeExtraKey( void * p_data, void * p_obj )
+{
+ VLC_UNUSED( p_obj );
+ free( p_data );
+}
+
+
static inline void vlc_meta_Set( vlc_meta_t * p_meta, vlc_meta_type_t meta_type, const char * psz_val )
{
free( p_meta->ppsz_meta[meta_type] );
int i;
for( i = 0; i < VLC_META_TYPE_COUNT ; i++ )
free( m->ppsz_meta[i] );
- vlc_dictionary_clear( &m->extra_tags );
+ vlc_dictionary_clear( &m->extra_tags, &vlc_meta_FreeExtraKey, NULL );
free( m );
}
if( psz_oldvalue != kVLCDictionaryNotFound )
{
free( psz_oldvalue );
- vlc_dictionary_remove_value_for_key( &m->extra_tags, psz_name );
+ vlc_dictionary_remove_value_for_key( &m->extra_tags, psz_name,
+ &vlc_meta_FreeExtraKey, NULL );
}
vlc_dictionary_insert( &m->extra_tags, psz_name, strdup(psz_value) );
}
for( i = 0; ppsz_all_keys[i]; i++ )
{
/* Always try to remove the previous value */
- vlc_dictionary_remove_value_for_key( &dst->extra_tags, ppsz_all_keys[i] );
+ vlc_dictionary_remove_value_for_key( &dst->extra_tags, ppsz_all_keys[i], NULL, NULL );
void * p_value = vlc_dictionary_value_for_key( &src->extra_tags, ppsz_all_keys[i] );
vlc_dictionary_insert( &dst->extra_tags, ppsz_all_keys[i], p_value );
free( ppsz_all_keys[i] );
services_discovery_RemoveItem( p_sd, p_item );
vlc_dictionary_remove_value_for_key(
&p_sys->services_name_to_input_item,
- name );
+ name, NULL, NULL );
}
}
}
if( p_sys->poll != NULL )
avahi_threaded_poll_free( p_sys->poll );
- vlc_dictionary_clear( &p_sys->services_name_to_input_item );
+ vlc_dictionary_clear( &p_sys->services_name_to_input_item, NULL, NULL );
free( p_sys );
return VLC_EGENERIC;
avahi_client_free( p_sys->client );
avahi_threaded_poll_free( p_sys->poll );
- vlc_dictionary_clear( &p_sys->services_name_to_input_item );
+ vlc_dictionary_clear( &p_sys->services_name_to_input_item, NULL, NULL );
free( p_sys );
}
}
free( all_keys );
- vlc_dictionary_clear( &p_mdis->catname_to_submedialist );
+ vlc_dictionary_clear( &p_mdis->catname_to_submedialist, NULL, NULL );
free( p_mdis );
}
CloseHandle( QUEUE.logfile );
#endif
- vlc_dictionary_clear( &priv->msg_enabled_objects );
+ vlc_dictionary_clear( &priv->msg_enabled_objects, NULL, NULL );
/* Destroy lock */
vlc_mutex_destroy( &QUEUE.lock );
test_dictionary_validity( &dict, our_keys, size );
- vlc_dictionary_remove_value_for_key( &dict, our_keys[size-1] );
+ vlc_dictionary_remove_value_for_key( &dict, our_keys[size-1], NULL, NULL );
test_dictionary_validity( &dict, our_keys, size-1 );
-
- vlc_dictionary_clear( &dict );
+
+ vlc_dictionary_clear( &dict, NULL, NULL );
assert( vlc_dictionary_keys_count( &dict ) == 0 );
return 0;