mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	Use pa_hashmap_remove_and_free() where appropriate
This commit is contained in:
		
							parent
							
								
									14e2553185
								
							
						
					
					
						commit
						eca082a93f
					
				
					 14 changed files with 29 additions and 84 deletions
				
			
		| 
						 | 
				
			
			@ -4296,10 +4296,8 @@ static void paths_drop_unused(pa_hashmap* h, pa_hashmap *keep) {
 | 
			
		|||
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -4468,17 +4466,13 @@ void pa_alsa_profile_set_drop_unsupported(pa_alsa_profile_set *ps) {
 | 
			
		|||
    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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -289,11 +289,7 @@ static int handle_event(struct userdata *u) {
 | 
			
		|||
                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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -144,12 +144,10 @@ static void free_session(struct session *session) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
static void remove_session(struct userdata *u, const char *id) {
 | 
			
		||||
    struct session *session;
 | 
			
		||||
    pa_assert(u);
 | 
			
		||||
    pa_assert(id);
 | 
			
		||||
 | 
			
		||||
    if (!(session = pa_hashmap_remove(u->sessions, id)))
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    free_session(session);
 | 
			
		||||
    pa_hashmap_remove_and_free(u->sessions, id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *message, void *userdata) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -949,8 +949,7 @@ static void handle_entry_remove(DBusConnection *conn, DBusMessage *msg, void *us
 | 
			
		|||
    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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -2099,7 +2098,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
 | 
			
		|||
 | 
			
		||||
                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);
 | 
			
		||||
| 
						 | 
				
			
			@ -2213,7 +2212,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
 | 
			
		|||
#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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -396,14 +396,11 @@ static void device_info_free(struct device_info *d) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -376,10 +376,8 @@ static void publish_service(pa_mainloop_api *api PA_GCC_UNUSED, void *service) {
 | 
			
		|||
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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -470,16 +468,11 @@ static pa_hook_result_t device_new_or_changed_cb(pa_core *c, pa_object *o, struc
 | 
			
		|||
 | 
			
		||||
/* 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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -129,16 +129,10 @@ const char *pa_headerlist_gets(pa_headerlist *p, const char *key) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
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) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -190,8 +190,7 @@ static void sink_input_kill(pa_sink_input* i) {
 | 
			
		|||
    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 */
 | 
			
		||||
| 
						 | 
				
			
			@ -647,10 +646,7 @@ static void sap_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event
 | 
			
		|||
        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 {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -687,10 +683,8 @@ static void check_death_event_cb(pa_mainloop_api *m, pa_time_event *t, const str
 | 
			
		|||
 | 
			
		||||
        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 */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -343,18 +343,15 @@ void pa_proplist_update(pa_proplist *p, pa_update_mode_t mode, const pa_proplist
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -322,18 +322,11 @@ int pa_database_set(pa_database *database, const pa_datum *key, const pa_datum*
 | 
			
		|||
 | 
			
		||||
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) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -993,8 +993,7 @@ void pa_dbus_protocol_add_signal_listener(
 | 
			
		|||
 | 
			
		||||
        /* 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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1324,13 +1324,9 @@ int pa_sink_input_remove_volume_factor(pa_sink_input *i, const char *key) {
 | 
			
		|||
    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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2547,9 +2547,7 @@ int pa_sink_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offse
 | 
			
		|||
                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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2630,8 +2628,7 @@ int pa_sink_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offse
 | 
			
		|||
            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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2070,9 +2070,7 @@ int pa_source_process_msg(pa_msgobject *object, int code, void *userdata, int64_
 | 
			
		|||
                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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue