p = pa_hashmap_iterate(h, &state, &key);
while (p) {
- if (pa_hashmap_get(keep, p) == NULL) {
- pa_hashmap_remove(h, key);
- pa_alsa_path_free(p);
- }
+ if (pa_hashmap_get(keep, p) == NULL)
+ pa_hashmap_remove_and_free(h, key);
p = pa_hashmap_iterate(h, &state, &key);
}
}
void *state;
PA_HASHMAP_FOREACH(p, ps->profiles, state) {
- if (!p->supported) {
- pa_hashmap_remove(ps->profiles, p->name);
- profile_free(p);
- }
+ if (!p->supported)
+ pa_hashmap_remove_and_free(ps->profiles, p->name);
}
PA_HASHMAP_FOREACH(m, ps->mappings, state) {
- if (m->supported <= 0) {
- pa_hashmap_remove(ps->mappings, m->name);
- mapping_free(m);
- }
+ if (m->supported <= 0)
+ pa_hashmap_remove_and_free(ps->mappings, m->name);
}
}
if (!(name = read_string(u)))
goto fail;
- if ((m = pa_hashmap_get(u->module_infos, name))) {
- pa_hashmap_remove(u->module_infos, name);
- module_info_free(m);
- }
-
+ pa_hashmap_remove_and_free(u->module_infos, name);
pa_xfree(name);
break;
}
static void remove_session(struct userdata *u, const char *id) {
- struct session *session;
-
- if (!(session = pa_hashmap_remove(u->sessions, id)))
- return;
+ pa_assert(u);
+ pa_assert(id);
- free_session(session);
+ pa_hashmap_remove_and_free(u->sessions, id);
}
static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, void *userdata) {
send_entry_removed_signal(de);
trigger_save(de->userdata);
- pa_assert_se(pa_hashmap_remove(de->userdata->dbus_entries, de->entry_name));
- dbus_entry_free(de);
+ pa_assert_se(pa_hashmap_remove_and_free(de->userdata->dbus_entries, de->entry_name) >= 0);
pa_dbus_send_empty_reply(conn, msg);
}
PA_HASHMAP_FOREACH(de, u->dbus_entries, state) {
send_entry_removed_signal(de);
- dbus_entry_free(pa_hashmap_remove(u->dbus_entries, de->entry_name));
+ pa_hashmap_remove_and_free(u->dbus_entries, de->entry_name);
}
#endif
pa_database_clear(u->database);
#ifdef HAVE_DBUS
if ((de = pa_hashmap_get(u->dbus_entries, name))) {
send_entry_removed_signal(de);
- dbus_entry_free(pa_hashmap_remove(u->dbus_entries, name));
+ pa_hashmap_remove_and_free(u->dbus_entries, name);
}
#endif
}
static pa_hook_result_t device_unlink_hook_cb(pa_core *c, pa_object *o, struct userdata *u) {
- struct device_info *d;
-
pa_assert(c);
pa_object_assert_ref(o);
pa_assert(u);
- if ((d = pa_hashmap_remove(u->device_infos, o)))
- device_info_free(d);
+ pa_hashmap_remove_and_free(u->device_infos, o);
return PA_HOOK_OK;
}
finish:
/* Remove this service */
- if (r < 0) {
- pa_hashmap_remove(s->userdata->services, s->key);
- service_free(s);
- }
+ if (r < 0)
+ pa_hashmap_remove_and_free(s->userdata->services, s->key);
avahi_string_list_free(txt);
}
/* Runs in PA mainloop context */
static pa_hook_result_t device_unlink_cb(pa_core *c, pa_object *o, struct userdata *u) {
- struct service *s;
-
pa_assert(c);
pa_object_assert_ref(o);
pa_threaded_mainloop_lock(u->mainloop);
-
- if ((s = pa_hashmap_remove(u->services, o)))
- service_free(s);
-
+ pa_hashmap_remove_and_free(u->services, o);
pa_threaded_mainloop_unlock(u->mainloop);
return PA_HOOK_OK;
}
int pa_headerlist_remove(pa_headerlist *p, const char *key) {
- struct header *hdr;
-
pa_assert(p);
pa_assert(key);
- if (!(hdr = pa_hashmap_remove(MAKE_HASHMAP(p), key)))
- return -1;
-
- header_free(hdr);
- return 0;
+ return pa_hashmap_remove_and_free(MAKE_HASHMAP(p), key);
}
const char *pa_headerlist_iterate(pa_headerlist *p, void **state) {
pa_sink_input_assert_ref(i);
pa_assert_se(s = i->userdata);
- pa_hashmap_remove(s->userdata->by_origin, s->sdp_info.origin);
- session_free(s);
+ pa_hashmap_remove_and_free(s->userdata->by_origin, s->sdp_info.origin);
}
/* Called from IO context */
return;
if (goodbye) {
-
- if ((s = pa_hashmap_remove(u->by_origin, info.origin)))
- session_free(s);
-
+ pa_hashmap_remove_and_free(u->by_origin, info.origin);
pa_sdp_info_destroy(&info);
} else {
k = pa_atomic_load(&s->timestamp);
- if (k + DEATH_TIMEOUT < now.tv_sec) {
- pa_hashmap_remove(u->by_origin, s->sdp_info.origin);
- session_free(s);
- }
+ if (k + DEATH_TIMEOUT < now.tv_sec)
+ pa_hashmap_remove_and_free(u->by_origin, s->sdp_info.origin);
}
/* Restart timer */
}
int pa_proplist_unset(pa_proplist *p, const char *key) {
- struct property *prop;
-
pa_assert(p);
pa_assert(key);
if (!pa_proplist_key_valid(key))
return -1;
- if (!(prop = pa_hashmap_remove(MAKE_HASHMAP(p), key)))
+ if (pa_hashmap_remove_and_free(MAKE_HASHMAP(p), key) < 0)
return -2;
- property_free(prop);
return 0;
}
int pa_database_unset(pa_database *database, const pa_datum *key) {
simple_data *db = (simple_data*)database;
- entry *e;
pa_assert(db);
pa_assert(key);
- e = pa_hashmap_remove(db->map, key);
- if (!e)
- return -1;
-
- free_entry(e);
-
- return 0;
+ return pa_hashmap_remove_and_free(db->map, key);
}
int pa_database_clear(pa_database *database) {
/* Replace the old signal paths entry for this signal with a new
* one. */
- if ((signal_paths_entry = pa_hashmap_remove(conn_entry->listening_signals, signal_name)))
- signal_paths_entry_free(signal_paths_entry);
+ pa_hashmap_remove_and_free(conn_entry->listening_signals, signal_name);
signal_paths_entry = signal_paths_entry_new(signal_name);
for (i = 0; i < n_objects; ++i)
pa_assert_ctl_context();
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
- v = pa_hashmap_remove(i->volume_factor_items, key);
-
- if (!v)
+ if (pa_hashmap_remove_and_free(i->volume_factor_items, key) < 0)
return -1;
- volume_factor_entry_free(v);
-
switch (pa_hashmap_size(i->volume_factor_items)) {
case 0:
pa_cvolume_reset(&i->volume_factor, i->sample_spec.channels);
i->thread_info.sync_next = NULL;
}
- if (pa_hashmap_remove(s->thread_info.inputs, PA_UINT32_TO_PTR(i->index)))
- pa_sink_input_unref(i);
-
+ pa_hashmap_remove_and_free(s->thread_info.inputs, PA_UINT32_TO_PTR(i->index));
pa_sink_invalidate_requested_latency(s, true);
pa_sink_request_rewind(s, (size_t) -1);
i->thread_info.attached = false;
/* Let's remove the sink input ...*/
- if (pa_hashmap_remove(s->thread_info.inputs, PA_UINT32_TO_PTR(i->index)))
- pa_sink_input_unref(i);
+ pa_hashmap_remove_and_free(s->thread_info.inputs, PA_UINT32_TO_PTR(i->index));
pa_sink_invalidate_requested_latency(s, true);
o->thread_info.direct_on_input = NULL;
}
- if (pa_hashmap_remove(s->thread_info.outputs, PA_UINT32_TO_PTR(o->index)))
- pa_source_output_unref(o);
-
+ pa_hashmap_remove_and_free(s->thread_info.outputs, PA_UINT32_TO_PTR(o->index));
pa_source_invalidate_requested_latency(s, true);
/* In flat volume mode we need to update the volume as