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.
This commit is contained in:
Tanu Kaskinen 2011-04-21 08:06:53 +03:00 committed by Colin Guthrie
parent 15257b0ec3
commit dcab6e1561

View file

@ -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->interfaces = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
obj_entry->introspection = NULL; 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; obj_entry_created = TRUE;
} }
@ -770,11 +770,6 @@ int pa_dbus_protocol_add_interface(pa_dbus_protocol *p,
return 0; return 0;
fail: fail:
if (obj_entry_created) {
pa_hashmap_remove(p->objects, path);
pa_xfree(obj_entry);
}
return -1; 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((pa_dbus_arg_info *) h->arguments);
pa_xfree(h);
} }
static void method_signature_free_cb(void *p, void *userdata) { 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))) while ((path = pa_idxset_steal_first(e->paths, NULL)))
pa_xfree(path); pa_xfree(path);
pa_idxset_free(e->paths, NULL, NULL);
pa_xfree(e); 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))) while ((object_path = pa_idxset_steal_first(conn_entry->all_signals_objects, NULL)))
pa_xfree(object_path); 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))) while ((signal_paths_entry = pa_hashmap_steal_first(conn_entry->listening_signals)))
signal_paths_entry_free(signal_paths_entry); signal_paths_entry_free(signal_paths_entry);
pa_hashmap_free(conn_entry->listening_signals, NULL, NULL);
pa_xfree(conn_entry); pa_xfree(conn_entry);
return 0; return 0;