mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-07 13:30:03 -05:00
hashmap: Add the ability to free keys
Since the hashmap stores a pointer to the key provided at pa_hashmap_put() time, it make sense to allow the hashmap to be given ownership of the key and have it free it at pa_hashmap_remove/free time. To do this cleanly, we now provide the key and value free functions at hashmap creation time with a pa_hashmap_new_full. With this, we do away with the free function that was provided at remove/free time for freeing the value.
This commit is contained in:
parent
317b46b571
commit
6825df8cec
41 changed files with 232 additions and 205 deletions
|
|
@ -52,11 +52,11 @@ static void header_free(struct header *hdr) {
|
|||
}
|
||||
|
||||
pa_headerlist* pa_headerlist_new(void) {
|
||||
return MAKE_HEADERLIST(pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func));
|
||||
return MAKE_HEADERLIST(pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) header_free));
|
||||
}
|
||||
|
||||
void pa_headerlist_free(pa_headerlist* p) {
|
||||
pa_hashmap_free(MAKE_HASHMAP(p), (pa_free_cb_t) header_free);
|
||||
pa_hashmap_free(MAKE_HASHMAP(p));
|
||||
}
|
||||
|
||||
int pa_headerlist_puts(pa_headerlist *p, const char *key, const char *value) {
|
||||
|
|
|
|||
|
|
@ -735,7 +735,7 @@ int pa__init(pa_module*m) {
|
|||
|
||||
PA_LLIST_HEAD_INIT(struct session, u->sessions);
|
||||
u->n_sessions = 0;
|
||||
u->by_origin = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
u->by_origin = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) session_free);
|
||||
|
||||
u->check_death_event = pa_core_rttime_new(m->core, pa_rtclock_now() + DEATH_TIMEOUT * PA_USEC_PER_SEC, check_death_event_cb, u);
|
||||
|
||||
|
|
@ -770,7 +770,7 @@ void pa__done(pa_module*m) {
|
|||
pa_sap_context_destroy(&u->sap_context);
|
||||
|
||||
if (u->by_origin)
|
||||
pa_hashmap_free(u->by_origin, (pa_free_cb_t) session_free);
|
||||
pa_hashmap_free(u->by_origin);
|
||||
|
||||
pa_xfree(u->sink_name);
|
||||
pa_xfree(u);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue