hashmap: Use pa_free_cb_t instead of pa_free2_cb_t

The previous patch removed module-gconf's dependency on the userdata
pointer of the free callback, and that was the only place where the
userdata pointer of pa_free2_cb_t was used, so now there's no need for
pa_free2_cb_t in pa_hashmap_free(). Using pa_free_cb_t instead allows
removing a significant amount of repetitive code.
This commit is contained in:
Tanu Kaskinen 2013-02-12 21:36:53 +02:00
parent dcf043842e
commit 8872c238ba
41 changed files with 112 additions and 308 deletions

View file

@ -530,7 +530,7 @@ void pa_alsa_path_set_free(pa_alsa_path_set *ps) {
pa_assert(ps); pa_assert(ps);
if (ps->paths) if (ps->paths)
pa_hashmap_free(ps->paths, NULL, NULL); pa_hashmap_free(ps->paths, NULL);
pa_xfree(ps); pa_xfree(ps);
} }
@ -3300,50 +3300,20 @@ static void profile_free(pa_alsa_profile *p) {
void pa_alsa_profile_set_free(pa_alsa_profile_set *ps) { void pa_alsa_profile_set_free(pa_alsa_profile_set *ps) {
pa_assert(ps); pa_assert(ps);
if (ps->input_paths) { if (ps->input_paths)
pa_alsa_path *p; pa_hashmap_free(ps->input_paths, (pa_free_cb_t) pa_alsa_path_free);
while ((p = pa_hashmap_steal_first(ps->input_paths))) if (ps->output_paths)
pa_alsa_path_free(p); pa_hashmap_free(ps->output_paths, (pa_free_cb_t) pa_alsa_path_free);
pa_hashmap_free(ps->input_paths, NULL, NULL); if (ps->profiles)
} pa_hashmap_free(ps->profiles, (pa_free_cb_t) profile_free);
if (ps->output_paths) { if (ps->mappings)
pa_alsa_path *p; pa_hashmap_free(ps->mappings, (pa_free_cb_t) mapping_free);
while ((p = pa_hashmap_steal_first(ps->output_paths))) if (ps->decibel_fixes)
pa_alsa_path_free(p); pa_hashmap_free(ps->decibel_fixes, (pa_free_cb_t) decibel_fix_free);
pa_hashmap_free(ps->output_paths, NULL, NULL);
}
if (ps->profiles) {
pa_alsa_profile *p;
while ((p = pa_hashmap_steal_first(ps->profiles)))
profile_free(p);
pa_hashmap_free(ps->profiles, NULL, NULL);
}
if (ps->mappings) {
pa_alsa_mapping *m;
while ((m = pa_hashmap_steal_first(ps->mappings)))
mapping_free(m);
pa_hashmap_free(ps->mappings, NULL, NULL);
}
if (ps->decibel_fixes) {
pa_alsa_decibel_fix *db_fix;
while ((db_fix = pa_hashmap_steal_first(ps->decibel_fixes)))
decibel_fix_free(db_fix);
pa_hashmap_free(ps->decibel_fixes, NULL, NULL);
}
pa_xfree(ps); pa_xfree(ps);
} }
@ -4415,8 +4385,8 @@ void pa_alsa_profile_set_probe(
paths_drop_unsupported(ps->input_paths); paths_drop_unsupported(ps->input_paths);
paths_drop_unsupported(ps->output_paths); paths_drop_unsupported(ps->output_paths);
pa_hashmap_free(broken_inputs, NULL, NULL); pa_hashmap_free(broken_inputs, NULL);
pa_hashmap_free(broken_outputs, NULL, NULL); pa_hashmap_free(broken_outputs, NULL);
ps->probed = TRUE; ps->probed = TRUE;
} }

View file

@ -744,7 +744,7 @@ void pa__done(pa_module*m) {
if (u->mixer_handle) if (u->mixer_handle)
snd_mixer_close(u->mixer_handle); snd_mixer_close(u->mixer_handle);
if (u->jacks) if (u->jacks)
pa_hashmap_free(u->jacks, NULL, NULL); pa_hashmap_free(u->jacks, NULL);
if (u->card && u->card->sinks) { if (u->card && u->card->sinks) {
pa_sink *s; pa_sink *s;

View file

@ -1736,12 +1736,12 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
if (y->devices) { if (y->devices) {
remove_all_devices(y); remove_all_devices(y);
pa_hashmap_free(y->devices, NULL, NULL); pa_hashmap_free(y->devices, NULL);
} }
if (y->transports) { if (y->transports) {
pa_assert(pa_hashmap_isempty(y->transports)); pa_assert(pa_hashmap_isempty(y->transports));
pa_hashmap_free(y->transports, NULL, NULL); pa_hashmap_free(y->transports, NULL);
} }
if (y->connection) { if (y->connection) {

View file

@ -184,7 +184,7 @@ void pa__done(pa_module* m) {
pa_xfree(mi); pa_xfree(mi);
} }
pa_hashmap_free(u->hashmap, NULL, NULL); pa_hashmap_free(u->hashmap, NULL);
} }
if (u->modargs) if (u->modargs)

View file

@ -466,14 +466,8 @@ void pa__done(pa_module*m) {
if (!(u = m->userdata)) if (!(u = m->userdata))
return; return;
if (u->bondings) { if (u->bondings)
struct bonding *b; pa_hashmap_free(u->bondings, (pa_free_cb_t) bonding_free);
while ((b = pa_hashmap_steal_first(u->bondings)))
bonding_free(b);
pa_hashmap_free(u->bondings, NULL, NULL);
}
if (u->dbus_connection) { if (u->dbus_connection) {
update_matches(u, false); update_matches(u, false);

View file

@ -543,14 +543,6 @@ pa_dbusiface_card *pa_dbusiface_card_new(pa_dbusiface_core *core, pa_card *card)
return c; return c;
} }
static void profile_free_cb(void *p, void *userdata) {
pa_dbusiface_card_profile *profile = p;
pa_assert(profile);
pa_dbusiface_card_profile_free(profile);
}
void pa_dbusiface_card_free(pa_dbusiface_card *c) { void pa_dbusiface_card_free(pa_dbusiface_card *c) {
pa_assert(c); pa_assert(c);
@ -558,7 +550,7 @@ void pa_dbusiface_card_free(pa_dbusiface_card *c) {
pa_hook_slot_free(c->card_profile_added_slot); pa_hook_slot_free(c->card_profile_added_slot);
pa_hashmap_free(c->profiles, profile_free_cb, NULL); pa_hashmap_free(c->profiles, (pa_free_cb_t) pa_dbusiface_card_profile_free);
pa_proplist_free(c->proplist); pa_proplist_free(c->proplist);
pa_dbus_protocol_unref(c->dbus_protocol); pa_dbus_protocol_unref(c->dbus_protocol);
pa_subscription_free(c->subscription); pa_subscription_free(c->subscription);

View file

@ -2089,54 +2089,6 @@ pa_dbusiface_core *pa_dbusiface_core_new(pa_core *core) {
return c; return c;
} }
static void free_card_cb(void *p, void *userdata) {
pa_dbusiface_card *c = p;
pa_assert(c);
pa_dbusiface_card_free(c);
}
static void free_device_cb(void *p, void *userdata) {
pa_dbusiface_device *d = p;
pa_assert(d);
pa_dbusiface_device_free(d);
}
static void free_stream_cb(void *p, void *userdata) {
pa_dbusiface_stream *s = p;
pa_assert(s);
pa_dbusiface_stream_free(s);
}
static void free_sample_cb(void *p, void *userdata) {
pa_dbusiface_sample *s = p;
pa_assert(s);
pa_dbusiface_sample_free(s);
}
static void free_module_cb(void *p, void *userdata) {
pa_dbusiface_module *m = p;
pa_assert(m);
pa_dbusiface_module_free(m);
}
static void free_client_cb(void *p, void *userdata) {
pa_dbusiface_client *c = p;
pa_assert(c);
pa_dbusiface_client_free(c);
}
void pa_dbusiface_core_free(pa_dbusiface_core *c) { void pa_dbusiface_core_free(pa_dbusiface_core *c) {
pa_assert(c); pa_assert(c);
@ -2145,16 +2097,16 @@ void pa_dbusiface_core_free(pa_dbusiface_core *c) {
/* Note that the order of freeing is important below. /* Note that the order of freeing is important below.
* Do not change it for the sake of tidiness without checking! */ * Do not change it for the sake of tidiness without checking! */
pa_subscription_free(c->subscription); pa_subscription_free(c->subscription);
pa_hashmap_free(c->cards, free_card_cb, NULL); pa_hashmap_free(c->cards, (pa_free_cb_t) pa_dbusiface_card_free);
pa_hashmap_free(c->sinks_by_path, NULL, NULL); pa_hashmap_free(c->sinks_by_path, NULL);
pa_hashmap_free(c->sinks_by_index, free_device_cb, NULL); pa_hashmap_free(c->sinks_by_index, (pa_free_cb_t) pa_dbusiface_device_free);
pa_hashmap_free(c->sources_by_path, NULL, NULL); pa_hashmap_free(c->sources_by_path, NULL);
pa_hashmap_free(c->sources_by_index, free_device_cb, NULL); pa_hashmap_free(c->sources_by_index, (pa_free_cb_t) pa_dbusiface_device_free);
pa_hashmap_free(c->playback_streams, free_stream_cb, NULL); pa_hashmap_free(c->playback_streams, (pa_free_cb_t) pa_dbusiface_stream_free);
pa_hashmap_free(c->record_streams, free_stream_cb, NULL); pa_hashmap_free(c->record_streams, (pa_free_cb_t) pa_dbusiface_stream_free);
pa_hashmap_free(c->samples, free_sample_cb, NULL); pa_hashmap_free(c->samples, (pa_free_cb_t) pa_dbusiface_sample_free);
pa_hashmap_free(c->modules, free_module_cb, NULL); pa_hashmap_free(c->modules, (pa_free_cb_t) pa_dbusiface_module_free);
pa_hashmap_free(c->clients, free_client_cb, NULL); pa_hashmap_free(c->clients, (pa_free_cb_t) pa_dbusiface_client_free);
pa_hook_slot_free(c->sink_put_slot); pa_hook_slot_free(c->sink_put_slot);
pa_hook_slot_free(c->sink_unlink_slot); pa_hook_slot_free(c->sink_unlink_slot);
pa_hook_slot_free(c->source_put_slot); pa_hook_slot_free(c->source_put_slot);

View file

@ -1266,14 +1266,6 @@ pa_dbusiface_device *pa_dbusiface_device_new_source(pa_dbusiface_core *core, pa_
return d; return d;
} }
static void port_free_cb(void *p, void *userdata) {
pa_dbusiface_device_port *port = p;
pa_assert(port);
pa_dbusiface_device_port_free(port);
}
void pa_dbusiface_device_free(pa_dbusiface_device *d) { void pa_dbusiface_device_free(pa_dbusiface_device *d) {
pa_assert(d); pa_assert(d);
@ -1287,7 +1279,7 @@ void pa_dbusiface_device_free(pa_dbusiface_device *d) {
pa_assert_se(pa_dbus_protocol_remove_interface(d->dbus_protocol, d->path, source_interface_info.name) >= 0); pa_assert_se(pa_dbus_protocol_remove_interface(d->dbus_protocol, d->path, source_interface_info.name) >= 0);
pa_source_unref(d->source); pa_source_unref(d->source);
} }
pa_hashmap_free(d->ports, port_free_cb, NULL); pa_hashmap_free(d->ports, (pa_free_cb_t) pa_dbusiface_device_port_free);
pa_proplist_free(d->proplist); pa_proplist_free(d->proplist);
pa_dbus_protocol_unref(d->dbus_protocol); pa_dbus_protocol_unref(d->dbus_protocol);
pa_subscription_free(d->subscription); pa_subscription_free(d->subscription);

View file

@ -200,7 +200,7 @@ static void load_module(
m->items[i].index = mod->index; m->items[i].index = mod->index;
} }
static void module_info_free(void *p, void *userdata) { static void module_info_free(void *p) {
struct module_info *m = p; struct module_info *m = p;
pa_assert(m); pa_assert(m);
@ -291,7 +291,7 @@ static int handle_event(struct userdata *u) {
if ((m = pa_hashmap_get(u->module_infos, name))) { if ((m = pa_hashmap_get(u->module_infos, name))) {
pa_hashmap_remove(u->module_infos, name); pa_hashmap_remove(u->module_infos, name);
module_info_free(m, u); module_info_free(m);
} }
pa_xfree(name); pa_xfree(name);
@ -401,7 +401,7 @@ void pa__done(pa_module*m) {
pa_close(u->fd); pa_close(u->fd);
if (u->module_infos) if (u->module_infos)
pa_hashmap_free(u->module_infos, module_info_free, NULL); pa_hashmap_free(u->module_infos, (pa_free_cb_t) module_info_free);
pa_xfree(u); pa_xfree(u);
} }

View file

@ -490,7 +490,7 @@ void pa__done(pa_module*m) {
unpublish_all_services(u); unpublish_all_services(u);
if (u->services) if (u->services)
pa_hashmap_free(u->services, NULL, NULL); pa_hashmap_free(u->services, NULL);
if (u->sink_new_slot) if (u->sink_new_slot)
pa_hook_slot_free(u->sink_new_slot); pa_hook_slot_free(u->sink_new_slot);

View file

@ -347,14 +347,8 @@ void pa__done(pa_module *m) {
if (u->client_proplist_changed_slot) if (u->client_proplist_changed_slot)
pa_hook_slot_free(u->client_proplist_changed_slot); pa_hook_slot_free(u->client_proplist_changed_slot);
if (u->cache) { if (u->cache)
struct rule *r; pa_hashmap_free(u->cache, (pa_free_cb_t) rule_free);
while ((r = pa_hashmap_steal_first(u->cache)))
rule_free(r);
pa_hashmap_free(u->cache, NULL, NULL);
}
pa_xfree(u); pa_xfree(u);
} }

View file

@ -136,7 +136,7 @@ static void port_info_update(struct port_info *p_info, pa_device_port *port) {
p_info->offset = port->latency_offset; p_info->offset = port->latency_offset;
} }
static void port_info_free(struct port_info *p_info, void *userdata) { static void port_info_free(struct port_info *p_info) {
pa_assert(p_info); pa_assert(p_info);
pa_xfree(p_info->name); pa_xfree(p_info->name);
@ -147,7 +147,7 @@ static void entry_free(struct entry* e) {
pa_assert(e); pa_assert(e);
pa_xfree(e->profile); pa_xfree(e->profile);
pa_hashmap_free(e->ports, (pa_free2_cb_t) port_info_free, NULL); pa_hashmap_free(e->ports, (pa_free_cb_t) port_info_free);
pa_xfree(e); pa_xfree(e);
} }

View file

@ -347,19 +347,14 @@ fail:
void pa__done(pa_module *m) { void pa__done(pa_module *m) {
struct userdata *u; struct userdata *u;
struct session *session;
pa_assert(m); pa_assert(m);
if (!(u = m->userdata)) if (!(u = m->userdata))
return; return;
if (u->sessions) { if (u->sessions)
while ((session = pa_hashmap_steal_first(u->sessions))) pa_hashmap_free(u->sessions, (pa_free_cb_t) free_session);
free_session(session);
pa_hashmap_free(u->sessions, NULL, NULL);
}
if (u->connection) { if (u->connection) {
pa_dbus_remove_matches( pa_dbus_remove_matches(

View file

@ -1302,7 +1302,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
pa_xfree(device); pa_xfree(device);
} }
pa_hashmap_free(h, NULL, NULL); pa_hashmap_free(h, NULL);
pa_log_error("Protocol error on reorder"); pa_log_error("Protocol error on reorder");
goto fail; goto fail;
} }
@ -1314,7 +1314,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
pa_xfree(device); pa_xfree(device);
} }
pa_hashmap_free(h, NULL, NULL); pa_hashmap_free(h, NULL);
pa_log_error("Client specified an unknown device in it's reorder list."); pa_log_error("Client specified an unknown device in it's reorder list.");
goto fail; goto fail;
} }
@ -1329,7 +1329,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
pa_xfree(device); pa_xfree(device);
} }
pa_hashmap_free(h, NULL, NULL); pa_hashmap_free(h, NULL);
pa_log_error("Attempted to reorder mixed devices (sinks and sources)"); pa_log_error("Attempted to reorder mixed devices (sinks and sources)");
goto fail; goto fail;
} }
@ -1402,7 +1402,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
while ((device = pa_hashmap_steal_first(h))) { while ((device = pa_hashmap_steal_first(h))) {
devices[idx++] = device; devices[idx++] = device;
} }
pa_hashmap_free(h, NULL, NULL); pa_hashmap_free(h, NULL);
/* Simple bubble sort */ /* Simple bubble sort */
for (i = 0; i < n_devices; ++i) { for (i = 0; i < n_devices; ++i) {

View file

@ -743,7 +743,7 @@ void pa__done(pa_module *m) {
filter_free(f); filter_free(f);
} }
pa_hashmap_free(u->filters, NULL, NULL); pa_hashmap_free(u->filters, NULL);
} }
pa_xfree(u); pa_xfree(u);

View file

@ -311,7 +311,7 @@ void pa__done(pa_module *m) {
pa_hook_slot_free(u->sink_input_move_finish_slot); pa_hook_slot_free(u->sink_input_move_finish_slot);
if (u->cork_state) if (u->cork_state)
pa_hashmap_free(u->cork_state, NULL, NULL); pa_hashmap_free(u->cork_state, NULL);
pa_xfree(u); pa_xfree(u);

View file

@ -2491,16 +2491,6 @@ fail:
return -1; return -1;
} }
#ifdef HAVE_DBUS
static void free_dbus_entry_cb(void *p, void *userdata) {
struct dbus_entry *de = p;
pa_assert(de);
dbus_entry_free(de);
}
#endif
void pa__done(pa_module*m) { void pa__done(pa_module*m) {
struct userdata* u; struct userdata* u;
@ -2516,7 +2506,7 @@ void pa__done(pa_module*m) {
pa_assert_se(pa_dbus_protocol_unregister_extension(u->dbus_protocol, INTERFACE_STREAM_RESTORE) >= 0); pa_assert_se(pa_dbus_protocol_unregister_extension(u->dbus_protocol, INTERFACE_STREAM_RESTORE) >= 0);
pa_assert_se(pa_dbus_protocol_remove_interface(u->dbus_protocol, OBJECT_PATH, stream_restore_interface_info.name) >= 0); pa_assert_se(pa_dbus_protocol_remove_interface(u->dbus_protocol, OBJECT_PATH, stream_restore_interface_info.name) >= 0);
pa_hashmap_free(u->dbus_entries, free_dbus_entry_cb, NULL); pa_hashmap_free(u->dbus_entries, (pa_free_cb_t) dbus_entry_free);
pa_dbus_protocol_unref(u->dbus_protocol); pa_dbus_protocol_unref(u->dbus_protocol);
} }

View file

@ -474,7 +474,6 @@ fail:
void pa__done(pa_module*m) { void pa__done(pa_module*m) {
struct userdata *u; struct userdata *u;
struct device_info *d;
pa_assert(m); pa_assert(m);
@ -519,10 +518,7 @@ void pa__done(pa_module*m) {
if (u->source_output_state_changed_slot) if (u->source_output_state_changed_slot)
pa_hook_slot_free(u->source_output_state_changed_slot); pa_hook_slot_free(u->source_output_state_changed_slot);
while ((d = pa_hashmap_steal_first(u->device_infos))) pa_hashmap_free(u->device_infos, (pa_free_cb_t) device_info_free);
device_info_free(d);
pa_hashmap_free(u->device_infos, NULL, NULL);
pa_xfree(u); pa_xfree(u);
} }

View file

@ -222,15 +222,8 @@ void pa__done(pa_module *m) {
return; return;
if (u->sessions) { if (u->sessions) {
while ((session = pa_hashmap_steal_first(u->sessions))) pa_hashmap_free(u->sessions, (pa_free_cb_t) free_session);
free_session(session); pa_hashmap_free(u->previous_sessions, (pa_free_cb_t) free_session);
pa_hashmap_free(u->sessions, NULL, NULL);
while ((session = pa_hashmap_steal_first(u->previous_sessions)))
free_session(session);
pa_hashmap_free(u->previous_sessions, NULL, NULL);
} }
if (u->io) if (u->io)

View file

@ -817,14 +817,8 @@ void pa__done(pa_module *m) {
if (u->inotify_fd >= 0) if (u->inotify_fd >= 0)
pa_close(u->inotify_fd); pa_close(u->inotify_fd);
if (u->devices) { if (u->devices)
struct device *d; pa_hashmap_free(u->devices, (pa_free_cb_t) device_free);
while ((d = pa_hashmap_steal_first(u->devices)))
device_free(d);
pa_hashmap_free(u->devices, NULL, NULL);
}
pa_xfree(u); pa_xfree(u);
} }

View file

@ -426,7 +426,7 @@ void pa__done(pa_module*m) {
tunnel_free(t); tunnel_free(t);
} }
pa_hashmap_free(u->tunnels, NULL, NULL); pa_hashmap_free(u->tunnels, NULL);
} }
pa_xfree(u); pa_xfree(u);

View file

@ -326,8 +326,10 @@ static int publish_service(struct service *s) {
finish: finish:
/* Remove this service */ /* Remove this service */
if (r < 0) if (r < 0) {
pa_hashmap_remove(s->userdata->services, s->device);
service_free(s); service_free(s);
}
avahi_string_list_free(txt); avahi_string_list_free(txt);
@ -374,8 +376,6 @@ static struct service *get_service(struct userdata *u, pa_object *device) {
static void service_free(struct service *s) { static void service_free(struct service *s) {
pa_assert(s); pa_assert(s);
pa_hashmap_remove(s->userdata->services, s->device);
if (s->entry_group) { if (s->entry_group) {
pa_log_debug("Removing entry group for %s.", s->service_name); pa_log_debug("Removing entry group for %s.", s->service_name);
avahi_entry_group_free(s->entry_group); avahi_entry_group_free(s->entry_group);
@ -413,7 +413,7 @@ static pa_hook_result_t device_unlink_cb(pa_core *c, pa_object *o, struct userda
pa_assert(c); pa_assert(c);
pa_object_assert_ref(o); pa_object_assert_ref(o);
if ((s = pa_hashmap_get(u->services, o))) if ((s = pa_hashmap_remove(u->services, o)))
service_free(s); service_free(s);
return PA_HOOK_OK; return PA_HOOK_OK;
@ -661,14 +661,8 @@ void pa__done(pa_module*m) {
if (!(u = m->userdata)) if (!(u = m->userdata))
return; return;
if (u->services) { if (u->services)
struct service *s; pa_hashmap_free(u->services, (pa_free_cb_t) service_free);
while ((s = pa_hashmap_first(u->services)))
service_free(s);
pa_hashmap_free(u->services, NULL, NULL);
}
if (u->sink_new_slot) if (u->sink_new_slot)
pa_hook_slot_free(u->sink_new_slot); pa_hook_slot_free(u->sink_new_slot);

View file

@ -381,7 +381,7 @@ void pa__done(pa_module*m) {
tunnel_free(t); tunnel_free(t);
} }
pa_hashmap_free(u->tunnels, NULL, NULL); pa_hashmap_free(u->tunnels, NULL);
} }
pa_xfree(u); pa_xfree(u);

View file

@ -56,12 +56,7 @@ pa_headerlist* pa_headerlist_new(void) {
} }
void pa_headerlist_free(pa_headerlist* p) { void pa_headerlist_free(pa_headerlist* p) {
struct header *hdr; pa_hashmap_free(MAKE_HASHMAP(p), (pa_free_cb_t) header_free);
while ((hdr = pa_hashmap_steal_first(MAKE_HASHMAP(p))))
header_free(hdr);
pa_hashmap_free(MAKE_HASHMAP(p), NULL, NULL);
} }
int pa_headerlist_puts(pa_headerlist *p, const char *key, const char *value) { int pa_headerlist_puts(pa_headerlist *p, const char *key, const char *value) {

View file

@ -186,6 +186,7 @@ static void sink_input_kill(pa_sink_input* i) {
pa_sink_input_assert_ref(i); pa_sink_input_assert_ref(i);
pa_assert_se(s = i->userdata); pa_assert_se(s = i->userdata);
pa_hashmap_remove(s->userdata->by_origin, s->sdp_info.origin);
session_free(s); session_free(s);
} }
@ -606,7 +607,6 @@ static void session_free(struct session *s) {
PA_LLIST_REMOVE(struct session, s->userdata->sessions, s); PA_LLIST_REMOVE(struct session, s->userdata->sessions, s);
pa_assert(s->userdata->n_sessions >= 1); pa_assert(s->userdata->n_sessions >= 1);
s->userdata->n_sessions--; s->userdata->n_sessions--;
pa_hashmap_remove(s->userdata->by_origin, s->sdp_info.origin);
pa_memblockq_free(s->memblockq); pa_memblockq_free(s->memblockq);
pa_sdp_info_destroy(&s->sdp_info); pa_sdp_info_destroy(&s->sdp_info);
@ -635,7 +635,7 @@ static void sap_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event
if (goodbye) { if (goodbye) {
if ((s = pa_hashmap_get(u->by_origin, info.origin))) if ((s = pa_hashmap_remove(u->by_origin, info.origin)))
session_free(s); session_free(s);
pa_sdp_info_destroy(&info); pa_sdp_info_destroy(&info);
@ -674,8 +674,10 @@ static void check_death_event_cb(pa_mainloop_api *m, pa_time_event *t, const str
k = pa_atomic_load(&s->timestamp); k = pa_atomic_load(&s->timestamp);
if (k + DEATH_TIMEOUT < now.tv_sec) if (k + DEATH_TIMEOUT < now.tv_sec) {
pa_hashmap_remove(u->by_origin, s->sdp_info.origin);
session_free(s); session_free(s);
}
} }
/* Restart timer */ /* Restart timer */
@ -753,7 +755,6 @@ fail:
void pa__done(pa_module*m) { void pa__done(pa_module*m) {
struct userdata *u; struct userdata *u;
struct session *s;
pa_assert(m); pa_assert(m);
@ -768,12 +769,8 @@ void pa__done(pa_module*m) {
pa_sap_context_destroy(&u->sap_context); pa_sap_context_destroy(&u->sap_context);
if (u->by_origin) { if (u->by_origin)
while ((s = pa_hashmap_first(u->by_origin))) pa_hashmap_free(u->by_origin, (pa_free_cb_t) session_free);
session_free(s);
pa_hashmap_free(u->by_origin, NULL, NULL);
}
pa_xfree(u->sink_name); pa_xfree(u->sink_name);
pa_xfree(u); pa_xfree(u);

View file

@ -241,9 +241,9 @@ static void context_free(pa_context *c) {
#endif #endif
if (c->record_streams) if (c->record_streams)
pa_hashmap_free(c->record_streams, NULL, NULL); pa_hashmap_free(c->record_streams, NULL);
if (c->playback_streams) if (c->playback_streams)
pa_hashmap_free(c->playback_streams, NULL, NULL); pa_hashmap_free(c->playback_streams, NULL);
if (c->mempool) if (c->mempool)
pa_mempool_free(c->mempool); pa_mempool_free(c->mempool);

View file

@ -70,8 +70,7 @@ pa_proplist* pa_proplist_new(void) {
void pa_proplist_free(pa_proplist* p) { void pa_proplist_free(pa_proplist* p) {
pa_assert(p); pa_assert(p);
pa_proplist_clear(p); pa_hashmap_free(MAKE_HASHMAP(p), (pa_free_cb_t) property_free);
pa_hashmap_free(MAKE_HASHMAP(p), NULL, NULL);
} }
/** Will accept only valid UTF-8 */ /** Will accept only valid UTF-8 */

View file

@ -57,7 +57,6 @@ pa_card_profile *pa_card_profile_new(const char *name, const char *description,
void pa_card_profile_free(pa_card_profile *c) { void pa_card_profile_free(pa_card_profile *c) {
pa_assert(c); pa_assert(c);
pa_assert(!c->card); /* Card profiles shouldn't be freed before removing them from the card. */
pa_xfree(c->name); pa_xfree(c->name);
pa_xfree(c->description); pa_xfree(c->description);
@ -126,14 +125,8 @@ void pa_card_new_data_done(pa_card_new_data *data) {
pa_proplist_free(data->proplist); pa_proplist_free(data->proplist);
if (data->profiles) { if (data->profiles)
pa_card_profile *c; pa_hashmap_free(data->profiles, (pa_free_cb_t) pa_card_profile_free);
while ((c = pa_hashmap_steal_first(data->profiles)))
pa_card_profile_free(c);
pa_hashmap_free(data->profiles, NULL, NULL);
}
if (data->ports) if (data->ports)
pa_device_port_hashmap_free(data->ports); pa_device_port_hashmap_free(data->ports);
@ -246,16 +239,8 @@ void pa_card_free(pa_card *c) {
pa_device_port_hashmap_free(c->ports); pa_device_port_hashmap_free(c->ports);
if (c->profiles) { if (c->profiles)
pa_card_profile *p; pa_hashmap_free(c->profiles, (pa_free_cb_t) pa_card_profile_free);
while ((p = pa_hashmap_steal_first(c->profiles))) {
p->card = NULL;
pa_card_profile_free(p);
}
pa_hashmap_free(c->profiles, NULL, NULL);
}
pa_proplist_free(c->proplist); pa_proplist_free(c->proplist);
pa_xfree(c->driver); pa_xfree(c->driver);

View file

@ -194,10 +194,10 @@ static void core_free(pa_object *o) {
pa_idxset_free(c->sink_inputs, NULL, NULL); pa_idxset_free(c->sink_inputs, NULL, NULL);
pa_assert(pa_hashmap_isempty(c->namereg)); pa_assert(pa_hashmap_isempty(c->namereg));
pa_hashmap_free(c->namereg, NULL, NULL); pa_hashmap_free(c->namereg, NULL);
pa_assert(pa_hashmap_isempty(c->shared)); pa_assert(pa_hashmap_isempty(c->shared));
pa_hashmap_free(c->shared, NULL, NULL); pa_hashmap_free(c->shared, NULL);
pa_subscription_free_all(c); pa_subscription_free_all(c);

View file

@ -264,10 +264,9 @@ void pa_database_close(pa_database *database) {
pa_assert(db); pa_assert(db);
pa_database_sync(database); pa_database_sync(database);
pa_database_clear(database);
pa_xfree(db->filename); pa_xfree(db->filename);
pa_xfree(db->tmp_filename); pa_xfree(db->tmp_filename);
pa_hashmap_free(db->map, NULL, NULL); pa_hashmap_free(db->map, (pa_free_cb_t) free_entry);
pa_xfree(db); pa_xfree(db);
} }

View file

@ -56,8 +56,10 @@ static void device_port_free(pa_object *o) {
if (p->proplist) if (p->proplist)
pa_proplist_free(p->proplist); pa_proplist_free(p->proplist);
if (p->profiles) if (p->profiles)
pa_hashmap_free(p->profiles, NULL, NULL); pa_hashmap_free(p->profiles, NULL);
pa_xfree(p->name); pa_xfree(p->name);
pa_xfree(p->description); pa_xfree(p->description);
pa_xfree(p); pa_xfree(p);
@ -88,14 +90,9 @@ pa_device_port *pa_device_port_new(pa_core *c, const char *name, const char *des
} }
void pa_device_port_hashmap_free(pa_hashmap *h) { void pa_device_port_hashmap_free(pa_hashmap *h) {
pa_device_port *p;
pa_assert(h); pa_assert(h);
while ((p = pa_hashmap_steal_first(h))) pa_hashmap_free(h, (pa_free_cb_t) pa_device_port_unref);
pa_device_port_unref(p);
pa_hashmap_free(h, NULL, NULL);
} }
void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) { void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {

View file

@ -101,7 +101,7 @@ static void remove_entry(pa_hashmap *h, struct hashmap_entry *e) {
h->n_entries--; h->n_entries--;
} }
void pa_hashmap_free(pa_hashmap*h, pa_free2_cb_t free_cb, void *userdata) { void pa_hashmap_free(pa_hashmap *h, pa_free_cb_t free_cb) {
pa_assert(h); pa_assert(h);
while (h->iterate_list_head) { while (h->iterate_list_head) {
@ -110,7 +110,7 @@ void pa_hashmap_free(pa_hashmap*h, pa_free2_cb_t free_cb, void *userdata) {
remove_entry(h, h->iterate_list_head); remove_entry(h, h->iterate_list_head);
if (free_cb) if (free_cb)
free_cb(data, userdata); free_cb(data);
} }
pa_xfree(h); pa_xfree(h);

View file

@ -22,6 +22,8 @@
USA. USA.
***/ ***/
#include <pulse/def.h>
#include <pulsecore/idxset.h> #include <pulsecore/idxset.h>
/* Simple Implementation of a hash table. Memory management is the /* Simple Implementation of a hash table. Memory management is the
@ -35,7 +37,7 @@ typedef struct pa_hashmap pa_hashmap;
pa_hashmap *pa_hashmap_new(pa_hash_func_t hash_func, pa_compare_func_t compare_func); pa_hashmap *pa_hashmap_new(pa_hash_func_t hash_func, pa_compare_func_t compare_func);
/* Free the hash table. Calls the specified function for every value in the table. The function may be NULL */ /* Free the hash table. Calls the specified function for every value in the table. The function may be NULL */
void pa_hashmap_free(pa_hashmap*, pa_free2_cb_t free_cb, void *userdata); void pa_hashmap_free(pa_hashmap*, pa_free_cb_t free_cb);
/* Add an entry to the hashmap. Returns non-zero when the entry already exists */ /* Add an entry to the hashmap. Returns non-zero when the entry already exists */
int pa_hashmap_put(pa_hashmap *h, const void *key, void *value); int pa_hashmap_put(pa_hashmap *h, const void *key, void *value);

View file

@ -964,8 +964,8 @@ void pa_memimport_free(pa_memimport *i) {
pa_mutex_unlock(i->pool->mutex); pa_mutex_unlock(i->pool->mutex);
pa_hashmap_free(i->blocks, NULL, NULL); pa_hashmap_free(i->blocks, NULL);
pa_hashmap_free(i->segments, NULL, NULL); pa_hashmap_free(i->segments, NULL);
pa_mutex_free(i->mutex); pa_mutex_free(i->mutex);

View file

@ -247,7 +247,7 @@ fail:
return NULL; return NULL;
} }
static void free_func(void *p, void*userdata) { static void free_func(void *p) {
struct entry *e = p; struct entry *e = p;
pa_assert(e); pa_assert(e);
@ -259,8 +259,8 @@ static void free_func(void *p, void*userdata) {
void pa_modargs_free(pa_modargs*ma) { void pa_modargs_free(pa_modargs*ma) {
pa_assert(ma); pa_assert(ma);
pa_hashmap_free(ma->raw, free_func, NULL); pa_hashmap_free(ma->raw, free_func);
pa_hashmap_free(ma->unescaped, free_func, NULL); pa_hashmap_free(ma->unescaped, free_func);
pa_xfree(ma); pa_xfree(ma);
} }

View file

@ -80,7 +80,7 @@ pa_cond *pa_cond_new(void) {
void pa_cond_free(pa_cond *c) { void pa_cond_free(pa_cond *c) {
assert(c); assert(c);
pa_hashmap_free(c->wait_events, NULL, NULL); pa_hashmap_free(c->wait_events, NULL);
pa_xfree(c); pa_xfree(c);
} }

View file

@ -169,8 +169,8 @@ void pa_dbus_protocol_unref(pa_dbus_protocol *p) {
pa_assert(pa_hashmap_isempty(p->connections)); pa_assert(pa_hashmap_isempty(p->connections));
pa_assert(pa_idxset_isempty(p->extensions)); pa_assert(pa_idxset_isempty(p->extensions));
pa_hashmap_free(p->objects, NULL, NULL); pa_hashmap_free(p->objects, NULL);
pa_hashmap_free(p->connections, NULL, NULL); pa_hashmap_free(p->connections, NULL);
pa_idxset_free(p->extensions, NULL, NULL); pa_idxset_free(p->extensions, NULL, NULL);
for (i = 0; i < PA_DBUS_PROTOCOL_HOOK_MAX; ++i) for (i = 0; i < PA_DBUS_PROTOCOL_HOOK_MAX; ++i)
@ -789,8 +789,7 @@ static void unregister_object(pa_dbus_protocol *p, struct object_entry *obj_entr
pa_assert_se(dbus_connection_unregister_object_path(conn_entry->connection, obj_entry->path)); pa_assert_se(dbus_connection_unregister_object_path(conn_entry->connection, obj_entry->path));
} }
static void method_handler_free_cb(void *p, void *userdata) { static void method_handler_free(pa_dbus_method_handler *h) {
pa_dbus_method_handler *h = p;
unsigned i; unsigned i;
pa_assert(h); pa_assert(h);
@ -807,15 +806,7 @@ static void method_handler_free_cb(void *p, void *userdata) {
pa_xfree(h); pa_xfree(h);
} }
static void method_signature_free_cb(void *p, void *userdata) { static void property_handler_free(pa_dbus_property_handler *h) {
pa_assert(p);
pa_xfree(p);
}
static void property_handler_free_cb(void *p, void *userdata) {
pa_dbus_property_handler *h = p;
pa_assert(h); pa_assert(h);
pa_xfree((char *) h->property_name); pa_xfree((char *) h->property_name);
@ -844,9 +835,9 @@ int pa_dbus_protocol_remove_interface(pa_dbus_protocol *p, const char* path, con
pa_log_debug("Interface %s removed from object %s", iface_entry->name, obj_entry->path); pa_log_debug("Interface %s removed from object %s", iface_entry->name, obj_entry->path);
pa_xfree(iface_entry->name); pa_xfree(iface_entry->name);
pa_hashmap_free(iface_entry->method_signatures, method_signature_free_cb, NULL); pa_hashmap_free(iface_entry->method_signatures, pa_xfree);
pa_hashmap_free(iface_entry->method_handlers, method_handler_free_cb, NULL); pa_hashmap_free(iface_entry->method_handlers, (pa_free_cb_t) method_handler_free);
pa_hashmap_free(iface_entry->property_handlers, property_handler_free_cb, NULL); pa_hashmap_free(iface_entry->property_handlers, (pa_free_cb_t) property_handler_free);
for (i = 0; i < iface_entry->n_signals; ++i) { for (i = 0; i < iface_entry->n_signals; ++i) {
unsigned j; unsigned j;
@ -870,7 +861,7 @@ int pa_dbus_protocol_remove_interface(pa_dbus_protocol *p, const char* path, con
pa_hashmap_remove(p->objects, path); pa_hashmap_remove(p->objects, path);
pa_xfree(obj_entry->path); pa_xfree(obj_entry->path);
pa_hashmap_free(obj_entry->interfaces, NULL, NULL); pa_hashmap_free(obj_entry->interfaces, NULL);
pa_xfree(obj_entry->introspection); pa_xfree(obj_entry->introspection);
pa_xfree(obj_entry); pa_xfree(obj_entry);
} }
@ -952,7 +943,6 @@ static void signal_paths_entry_free(struct signal_paths_entry *e) {
int pa_dbus_protocol_unregister_connection(pa_dbus_protocol *p, DBusConnection *conn) { int pa_dbus_protocol_unregister_connection(pa_dbus_protocol *p, DBusConnection *conn) {
struct connection_entry *conn_entry = NULL; struct connection_entry *conn_entry = NULL;
struct signal_paths_entry *signal_paths_entry = NULL;
char *object_path = NULL; char *object_path = NULL;
pa_assert(p); pa_assert(p);
@ -970,10 +960,7 @@ int pa_dbus_protocol_unregister_connection(pa_dbus_protocol *p, DBusConnection *
pa_idxset_free(conn_entry->all_signals_objects, NULL, NULL); pa_idxset_free(conn_entry->all_signals_objects, NULL, NULL);
while ((signal_paths_entry = pa_hashmap_steal_first(conn_entry->listening_signals))) pa_hashmap_free(conn_entry->listening_signals, (pa_free_cb_t) signal_paths_entry_free);
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;

View file

@ -5100,7 +5100,7 @@ void pa_native_protocol_unref(pa_native_protocol *p) {
for (h = 0; h < PA_NATIVE_HOOK_MAX; h++) for (h = 0; h < PA_NATIVE_HOOK_MAX; h++)
pa_hook_done(&p->hooks[h]); pa_hook_done(&p->hooks[h]);
pa_hashmap_free(p->extensions, NULL, NULL); pa_hashmap_free(p->extensions, NULL);
pa_assert_se(pa_shared_remove(p->core, "native-protocol") >= 0); pa_assert_se(pa_shared_remove(p->core, "native-protocol") >= 0);

View file

@ -74,10 +74,6 @@ static void volume_factor_entry_free(struct volume_factor_entry *volume_entry) {
pa_xfree(volume_entry); pa_xfree(volume_entry);
} }
static void volume_factor_entry_free2(struct volume_factor_entry *volume_entry, void *userdarta) {
volume_factor_entry_free(volume_entry);
}
static void volume_factor_from_hashmap(pa_cvolume *v, pa_hashmap *items, uint8_t channels) { static void volume_factor_from_hashmap(pa_cvolume *v, pa_hashmap *items, uint8_t channels) {
struct volume_factor_entry *entry; struct volume_factor_entry *entry;
void *state = NULL; void *state = NULL;
@ -245,10 +241,10 @@ void pa_sink_input_new_data_done(pa_sink_input_new_data *data) {
pa_format_info_free(data->format); pa_format_info_free(data->format);
if (data->volume_factor_items) if (data->volume_factor_items)
pa_hashmap_free(data->volume_factor_items, (pa_free2_cb_t) volume_factor_entry_free2, NULL); pa_hashmap_free(data->volume_factor_items, (pa_free_cb_t) volume_factor_entry_free);
if (data->volume_factor_sink_items) if (data->volume_factor_sink_items)
pa_hashmap_free(data->volume_factor_sink_items, (pa_free2_cb_t) volume_factor_entry_free2, NULL); pa_hashmap_free(data->volume_factor_sink_items, (pa_free_cb_t) volume_factor_entry_free);
pa_proplist_free(data->proplist); pa_proplist_free(data->proplist);
} }
@ -745,12 +741,13 @@ static void sink_input_free(pa_object *o) {
pa_idxset_free(i->direct_outputs, NULL, NULL); pa_idxset_free(i->direct_outputs, NULL, NULL);
if (i->thread_info.direct_outputs) if (i->thread_info.direct_outputs)
pa_hashmap_free(i->thread_info.direct_outputs, NULL, NULL); pa_hashmap_free(i->thread_info.direct_outputs, NULL);
if (i->volume_factor_items) if (i->volume_factor_items)
pa_hashmap_free(i->volume_factor_items, (pa_free2_cb_t) volume_factor_entry_free2, NULL); pa_hashmap_free(i->volume_factor_items, (pa_free_cb_t) volume_factor_entry_free);
if (i->volume_factor_sink_items) if (i->volume_factor_sink_items)
pa_hashmap_free(i->volume_factor_sink_items, (pa_free2_cb_t) volume_factor_entry_free2, NULL); pa_hashmap_free(i->volume_factor_sink_items, (pa_free_cb_t) volume_factor_entry_free);
pa_xfree(i->driver); pa_xfree(i->driver);
pa_xfree(i); pa_xfree(i);

View file

@ -715,7 +715,6 @@ void pa_sink_unlink(pa_sink* s) {
/* Called from main context */ /* Called from main context */
static void sink_free(pa_object *o) { static void sink_free(pa_object *o) {
pa_sink *s = PA_SINK(o); pa_sink *s = PA_SINK(o);
pa_sink_input *i;
pa_assert(s); pa_assert(s);
pa_assert_ctl_context(); pa_assert_ctl_context();
@ -732,11 +731,7 @@ static void sink_free(pa_object *o) {
} }
pa_idxset_free(s->inputs, NULL, NULL); pa_idxset_free(s->inputs, NULL, NULL);
pa_hashmap_free(s->thread_info.inputs, (pa_free_cb_t) pa_sink_input_unref);
while ((i = pa_hashmap_steal_first(s->thread_info.inputs)))
pa_sink_input_unref(i);
pa_hashmap_free(s->thread_info.inputs, NULL, NULL);
if (s->silence.memblock) if (s->silence.memblock)
pa_memblock_unref(s->silence.memblock); pa_memblock_unref(s->silence.memblock);

View file

@ -648,7 +648,6 @@ void pa_source_unlink(pa_source *s) {
/* Called from main context */ /* Called from main context */
static void source_free(pa_object *o) { static void source_free(pa_object *o) {
pa_source_output *so;
pa_source *s = PA_SOURCE(o); pa_source *s = PA_SOURCE(o);
pa_assert(s); pa_assert(s);
@ -661,11 +660,7 @@ static void source_free(pa_object *o) {
pa_log_info("Freeing source %u \"%s\"", s->index, s->name); pa_log_info("Freeing source %u \"%s\"", s->index, s->name);
pa_idxset_free(s->outputs, NULL, NULL); pa_idxset_free(s->outputs, NULL, NULL);
pa_hashmap_free(s->thread_info.outputs, (pa_free_cb_t) pa_source_output_unref);
while ((so = pa_hashmap_steal_first(s->thread_info.outputs)))
pa_source_output_unref(so);
pa_hashmap_free(s->thread_info.outputs, NULL, NULL);
if (s->silence.memblock) if (s->silence.memblock)
pa_memblock_unref(s->silence.memblock); pa_memblock_unref(s->silence.memblock);