[vlc-devel] [PATCH] dbus: Prevent dictionary from growing out of control
Casian Andrei
skeletk13 at gmail.com
Tue Feb 21 20:40:23 CET 2012
For each item that was appended or deleted, the ("Tracks", NULL) pair
was inserted (duplicated over and over) in the tracklist_properties
dictionary. The dictionary was inserting it in the same position and
it assumed it had hash collisions, triggering an expansion at every
insertion of that pair.
Create a has_key function for the dictionary.
Check if the key is present before inserting in the dict again, at
playlist_item_append, playlist_item_deleted events.
---
include/vlc_arrays.h | 8 ++++++++
modules/control/dbus/dbus.c | 3 ++-
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/include/vlc_arrays.h b/include/vlc_arrays.h
index 68ea1e2..6643197 100644
--- a/include/vlc_arrays.h
+++ b/include/vlc_arrays.h
@@ -451,7 +451,15 @@ static inline void vlc_dictionary_clear(
vlc_dictionary_t * p_dict,
p_dict->i_size = 0;
}
+static inline int
+vlc_dictionary_has_key( const vlc_dictionary_t * p_dict, const char *
psz_key )
+{
+ if( !p_dict->p_entries )
+ return 0;
+ int i_pos = DictHash( psz_key, p_dict->i_size );
+ return p_dict->p_entries[i_pos] != NULL;
+}
static inline void *
vlc_dictionary_value_for_key( const vlc_dictionary_t * p_dict, const char
* psz_key )
diff --git a/modules/control/dbus/dbus.c b/modules/control/dbus/dbus.c
index 21945e2..f8b3377 100644
--- a/modules/control/dbus/dbus.c
+++ b/modules/control/dbus/dbus.c
@@ -556,7 +556,8 @@ static void ProcessEvents( intf_thread_t *p_intf,
vlc_dictionary_insert( &player_properties, "CanPlay", NULL
);
}
- vlc_dictionary_insert( &tracklist_properties, "Tracks", NULL );
+ if( !vlc_dictionary_has_key( &tracklist_properties, "Tracks" )
)
+ vlc_dictionary_insert( &tracklist_properties, "Tracks",
NULL );
break;
case SIGNAL_VOLUME_MUTED:
case SIGNAL_VOLUME_CHANGE:
--
1.7.7
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20120221/de425b7f/attachment.html>
More information about the vlc-devel
mailing list