From dcab6e15618ff44d814d29aaf92ade6613c70657 Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Thu, 21 Apr 2011 08:06:53 +0300 Subject: protocol-dbus: Fix some memory management bugs. There were several memory leaks. In addition to those, pa_dbus_protocol_add_interface() used a string from the caller as a key to a hashmap, instead of a copy of the string. This caused trouble when the caller freed the string while the key was still in use in the hashmap. --- src/pulsecore/protocol-dbus.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/pulsecore/protocol-dbus.c b/src/pulsecore/protocol-dbus.c index c3299157..8784c345 100644 --- a/src/pulsecore/protocol-dbus.c +++ b/src/pulsecore/protocol-dbus.c @@ -742,7 +742,7 @@ int pa_dbus_protocol_add_interface(pa_dbus_protocol *p, obj_entry->interfaces = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); obj_entry->introspection = NULL; - pa_hashmap_put(p->objects, path, obj_entry); + pa_hashmap_put(p->objects, obj_entry->path, obj_entry); obj_entry_created = TRUE; } @@ -770,11 +770,6 @@ int pa_dbus_protocol_add_interface(pa_dbus_protocol *p, return 0; fail: - if (obj_entry_created) { - pa_hashmap_remove(p->objects, path); - pa_xfree(obj_entry); - } - return -1; } @@ -804,6 +799,7 @@ static void method_handler_free_cb(void *p, void *userdata) { } pa_xfree((pa_dbus_arg_info *) h->arguments); + pa_xfree(h); } static void method_signature_free_cb(void *p, void *userdata) { @@ -945,6 +941,7 @@ static void signal_paths_entry_free(struct signal_paths_entry *e) { while ((path = pa_idxset_steal_first(e->paths, NULL))) pa_xfree(path); + pa_idxset_free(e->paths, NULL, NULL); pa_xfree(e); } @@ -966,9 +963,12 @@ int pa_dbus_protocol_unregister_connection(pa_dbus_protocol *p, DBusConnection * while ((object_path = pa_idxset_steal_first(conn_entry->all_signals_objects, NULL))) pa_xfree(object_path); + pa_idxset_free(conn_entry->all_signals_objects, NULL, NULL); + while ((signal_paths_entry = pa_hashmap_steal_first(conn_entry->listening_signals))) signal_paths_entry_free(signal_paths_entry); + pa_hashmap_free(conn_entry->listening_signals, NULL, NULL); pa_xfree(conn_entry); return 0; -- cgit