[pulseaudio-discuss] [PATCH 03/13] hashmap: Use pa_free_cb_t instead of pa_free2_cb_t

Tanu Kaskinen tanuk at iki.fi
Tue Feb 12 11:36:53 PST 2013


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.
---
 src/modules/alsa/alsa-mixer.c                      |   56 ++++------------
 src/modules/alsa/module-alsa-card.c                |    2 +-
 src/modules/bluetooth/bluetooth-util.c             |    4 +-
 src/modules/bluetooth/module-bluetooth-discover.c  |    2 +-
 src/modules/bluetooth/module-bluetooth-proximity.c |   10 +--
 src/modules/dbus/iface-card.c                      |   10 +--
 src/modules/dbus/iface-core.c                      |   68 +++-----------------
 src/modules/dbus/iface-device.c                    |   10 +--
 src/modules/gconf/module-gconf.c                   |    6 +-
 src/modules/macosx/module-bonjour-publish.c        |    2 +-
 src/modules/module-augment-properties.c            |   10 +--
 src/modules/module-card-restore.c                  |    4 +-
 src/modules/module-console-kit.c                   |    9 +--
 src/modules/module-device-manager.c                |    8 +--
 src/modules/module-filter-apply.c                  |    2 +-
 src/modules/module-role-cork.c                     |    2 +-
 src/modules/module-stream-restore.c                |   12 +---
 src/modules/module-suspend-on-idle.c               |    6 +-
 src/modules/module-systemd-login.c                 |   11 +---
 src/modules/module-udev-detect.c                   |   10 +--
 src/modules/module-zeroconf-discover.c             |    2 +-
 src/modules/module-zeroconf-publish.c              |   18 ++----
 src/modules/raop/module-raop-discover.c            |    2 +-
 src/modules/rtp/headerlist.c                       |    7 +-
 src/modules/rtp/module-rtp-recv.c                  |   17 ++---
 src/pulse/context.c                                |    4 +-
 src/pulse/proplist.c                               |    3 +-
 src/pulsecore/card.c                               |   23 ++-----
 src/pulsecore/core.c                               |    4 +-
 src/pulsecore/database-simple.c                    |    3 +-
 src/pulsecore/device-port.c                        |   11 ++--
 src/pulsecore/hashmap.c                            |    4 +-
 src/pulsecore/hashmap.h                            |    4 +-
 src/pulsecore/memblock.c                           |    4 +-
 src/pulsecore/modargs.c                            |    6 +-
 src/pulsecore/mutex-win32.c                        |    2 +-
 src/pulsecore/protocol-dbus.c                      |   31 +++------
 src/pulsecore/protocol-native.c                    |    2 +-
 src/pulsecore/sink-input.c                         |   15 ++---
 src/pulsecore/sink.c                               |    7 +-
 src/pulsecore/source.c                             |    7 +-
 41 files changed, 112 insertions(+), 308 deletions(-)

diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 761aae1..395ee2c 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -530,7 +530,7 @@ void pa_alsa_path_set_free(pa_alsa_path_set *ps) {
     pa_assert(ps);
 
     if (ps->paths)
-        pa_hashmap_free(ps->paths, NULL, NULL);
+        pa_hashmap_free(ps->paths, NULL);
 
     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) {
     pa_assert(ps);
 
-    if (ps->input_paths) {
-        pa_alsa_path *p;
-
-        while ((p = pa_hashmap_steal_first(ps->input_paths)))
-            pa_alsa_path_free(p);
-
-        pa_hashmap_free(ps->input_paths, NULL, NULL);
-    }
-
-    if (ps->output_paths) {
-        pa_alsa_path *p;
-
-        while ((p = pa_hashmap_steal_first(ps->output_paths)))
-            pa_alsa_path_free(p);
-
-        pa_hashmap_free(ps->output_paths, NULL, NULL);
-    }
+    if (ps->input_paths)
+        pa_hashmap_free(ps->input_paths, (pa_free_cb_t) pa_alsa_path_free);
 
-    if (ps->profiles) {
-        pa_alsa_profile *p;
+    if (ps->output_paths)
+        pa_hashmap_free(ps->output_paths, (pa_free_cb_t) pa_alsa_path_free);
 
-        while ((p = pa_hashmap_steal_first(ps->profiles)))
-            profile_free(p);
-
-        pa_hashmap_free(ps->profiles, NULL, NULL);
-    }
+    if (ps->profiles)
+        pa_hashmap_free(ps->profiles, (pa_free_cb_t) profile_free);
 
-    if (ps->mappings) {
-        pa_alsa_mapping *m;
-
-        while ((m = pa_hashmap_steal_first(ps->mappings)))
-            mapping_free(m);
+    if (ps->mappings)
+        pa_hashmap_free(ps->mappings, (pa_free_cb_t) mapping_free);
 
-        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);
-    }
+    if (ps->decibel_fixes)
+        pa_hashmap_free(ps->decibel_fixes, (pa_free_cb_t) decibel_fix_free);
 
     pa_xfree(ps);
 }
@@ -4415,8 +4385,8 @@ void pa_alsa_profile_set_probe(
 
     paths_drop_unsupported(ps->input_paths);
     paths_drop_unsupported(ps->output_paths);
-    pa_hashmap_free(broken_inputs, NULL, NULL);
-    pa_hashmap_free(broken_outputs, NULL, NULL);
+    pa_hashmap_free(broken_inputs, NULL);
+    pa_hashmap_free(broken_outputs, NULL);
 
     ps->probed = TRUE;
 }
diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c
index 366f4ba..3c995f8 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -744,7 +744,7 @@ void pa__done(pa_module*m) {
     if (u->mixer_handle)
         snd_mixer_close(u->mixer_handle);
     if (u->jacks)
-        pa_hashmap_free(u->jacks, NULL, NULL);
+        pa_hashmap_free(u->jacks, NULL);
 
     if (u->card && u->card->sinks) {
         pa_sink *s;
diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 98e795c..776f092 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -1736,12 +1736,12 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
 
     if (y->devices) {
         remove_all_devices(y);
-        pa_hashmap_free(y->devices, NULL, NULL);
+        pa_hashmap_free(y->devices, NULL);
     }
 
     if (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) {
diff --git a/src/modules/bluetooth/module-bluetooth-discover.c b/src/modules/bluetooth/module-bluetooth-discover.c
index eb59beb..cbd56cc 100644
--- a/src/modules/bluetooth/module-bluetooth-discover.c
+++ b/src/modules/bluetooth/module-bluetooth-discover.c
@@ -184,7 +184,7 @@ void pa__done(pa_module* m) {
             pa_xfree(mi);
         }
 
-        pa_hashmap_free(u->hashmap, NULL, NULL);
+        pa_hashmap_free(u->hashmap, NULL);
     }
 
     if (u->modargs)
diff --git a/src/modules/bluetooth/module-bluetooth-proximity.c b/src/modules/bluetooth/module-bluetooth-proximity.c
index 7f90951..b55dfdb 100644
--- a/src/modules/bluetooth/module-bluetooth-proximity.c
+++ b/src/modules/bluetooth/module-bluetooth-proximity.c
@@ -466,14 +466,8 @@ void pa__done(pa_module*m) {
     if (!(u = m->userdata))
         return;
 
-    if (u->bondings) {
-        struct bonding *b;
-
-        while ((b = pa_hashmap_steal_first(u->bondings)))
-            bonding_free(b);
-
-        pa_hashmap_free(u->bondings, NULL, NULL);
-    }
+    if (u->bondings)
+        pa_hashmap_free(u->bondings, (pa_free_cb_t) bonding_free);
 
     if (u->dbus_connection) {
         update_matches(u, false);
diff --git a/src/modules/dbus/iface-card.c b/src/modules/dbus/iface-card.c
index 1313e71..945f5bb 100644
--- a/src/modules/dbus/iface-card.c
+++ b/src/modules/dbus/iface-card.c
@@ -543,14 +543,6 @@ pa_dbusiface_card *pa_dbusiface_card_new(pa_dbusiface_core *core, pa_card *card)
     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) {
     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_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_dbus_protocol_unref(c->dbus_protocol);
     pa_subscription_free(c->subscription);
diff --git a/src/modules/dbus/iface-core.c b/src/modules/dbus/iface-core.c
index 97a46a5..a9716bc 100644
--- a/src/modules/dbus/iface-core.c
+++ b/src/modules/dbus/iface-core.c
@@ -2089,54 +2089,6 @@ pa_dbusiface_core *pa_dbusiface_core_new(pa_core *core) {
     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) {
     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.
      * Do not change it for the sake of tidiness without checking! */
     pa_subscription_free(c->subscription);
-    pa_hashmap_free(c->cards, free_card_cb, NULL);
-    pa_hashmap_free(c->sinks_by_path, NULL, NULL);
-    pa_hashmap_free(c->sinks_by_index, free_device_cb, NULL);
-    pa_hashmap_free(c->sources_by_path, NULL, NULL);
-    pa_hashmap_free(c->sources_by_index, free_device_cb, NULL);
-    pa_hashmap_free(c->playback_streams, free_stream_cb, NULL);
-    pa_hashmap_free(c->record_streams, free_stream_cb, NULL);
-    pa_hashmap_free(c->samples, free_sample_cb, NULL);
-    pa_hashmap_free(c->modules, free_module_cb, NULL);
-    pa_hashmap_free(c->clients, free_client_cb, NULL);
+    pa_hashmap_free(c->cards, (pa_free_cb_t) pa_dbusiface_card_free);
+    pa_hashmap_free(c->sinks_by_path, NULL);
+    pa_hashmap_free(c->sinks_by_index, (pa_free_cb_t) pa_dbusiface_device_free);
+    pa_hashmap_free(c->sources_by_path, NULL);
+    pa_hashmap_free(c->sources_by_index, (pa_free_cb_t) pa_dbusiface_device_free);
+    pa_hashmap_free(c->playback_streams, (pa_free_cb_t) pa_dbusiface_stream_free);
+    pa_hashmap_free(c->record_streams, (pa_free_cb_t) pa_dbusiface_stream_free);
+    pa_hashmap_free(c->samples, (pa_free_cb_t) pa_dbusiface_sample_free);
+    pa_hashmap_free(c->modules, (pa_free_cb_t) pa_dbusiface_module_free);
+    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_unlink_slot);
     pa_hook_slot_free(c->source_put_slot);
diff --git a/src/modules/dbus/iface-device.c b/src/modules/dbus/iface-device.c
index 151938d..888d407 100644
--- a/src/modules/dbus/iface-device.c
+++ b/src/modules/dbus/iface-device.c
@@ -1266,14 +1266,6 @@ pa_dbusiface_device *pa_dbusiface_device_new_source(pa_dbusiface_core *core, pa_
     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) {
     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_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_dbus_protocol_unref(d->dbus_protocol);
     pa_subscription_free(d->subscription);
diff --git a/src/modules/gconf/module-gconf.c b/src/modules/gconf/module-gconf.c
index 5304116..c60d0f0 100644
--- a/src/modules/gconf/module-gconf.c
+++ b/src/modules/gconf/module-gconf.c
@@ -200,7 +200,7 @@ static void load_module(
     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;
 
     pa_assert(m);
@@ -291,7 +291,7 @@ static int handle_event(struct userdata *u) {
 
                 if ((m = pa_hashmap_get(u->module_infos, name))) {
                     pa_hashmap_remove(u->module_infos, name);
-                    module_info_free(m, u);
+                    module_info_free(m);
                 }
 
                 pa_xfree(name);
@@ -401,7 +401,7 @@ void pa__done(pa_module*m) {
         pa_close(u->fd);
 
     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);
 }
diff --git a/src/modules/macosx/module-bonjour-publish.c b/src/modules/macosx/module-bonjour-publish.c
index 667b6b7..d29d518 100644
--- a/src/modules/macosx/module-bonjour-publish.c
+++ b/src/modules/macosx/module-bonjour-publish.c
@@ -490,7 +490,7 @@ void pa__done(pa_module*m) {
     unpublish_all_services(u);
 
     if (u->services)
-        pa_hashmap_free(u->services, NULL, NULL);
+        pa_hashmap_free(u->services, NULL);
 
     if (u->sink_new_slot)
         pa_hook_slot_free(u->sink_new_slot);
diff --git a/src/modules/module-augment-properties.c b/src/modules/module-augment-properties.c
index 6bba2b3..ee3b54c 100644
--- a/src/modules/module-augment-properties.c
+++ b/src/modules/module-augment-properties.c
@@ -347,14 +347,8 @@ void pa__done(pa_module *m) {
     if (u->client_proplist_changed_slot)
         pa_hook_slot_free(u->client_proplist_changed_slot);
 
-    if (u->cache) {
-        struct rule *r;
-
-        while ((r = pa_hashmap_steal_first(u->cache)))
-            rule_free(r);
-
-        pa_hashmap_free(u->cache, NULL, NULL);
-    }
+    if (u->cache)
+        pa_hashmap_free(u->cache, (pa_free_cb_t) rule_free);
 
     pa_xfree(u);
 }
diff --git a/src/modules/module-card-restore.c b/src/modules/module-card-restore.c
index 51923fd..3b061b6 100644
--- a/src/modules/module-card-restore.c
+++ b/src/modules/module-card-restore.c
@@ -136,7 +136,7 @@ static void port_info_update(struct port_info *p_info, pa_device_port *port) {
     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_xfree(p_info->name);
@@ -147,7 +147,7 @@ static void entry_free(struct entry* e) {
     pa_assert(e);
 
     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);
 }
diff --git a/src/modules/module-console-kit.c b/src/modules/module-console-kit.c
index 29f7e66..c9c2f45 100644
--- a/src/modules/module-console-kit.c
+++ b/src/modules/module-console-kit.c
@@ -347,19 +347,14 @@ fail:
 
 void pa__done(pa_module *m) {
     struct userdata *u;
-    struct session *session;
 
     pa_assert(m);
 
     if (!(u = m->userdata))
         return;
 
-    if (u->sessions) {
-        while ((session = pa_hashmap_steal_first(u->sessions)))
-            free_session(session);
-
-        pa_hashmap_free(u->sessions, NULL, NULL);
-    }
+    if (u->sessions)
+        pa_hashmap_free(u->sessions, (pa_free_cb_t) free_session);
 
     if (u->connection) {
         pa_dbus_remove_matches(
diff --git a/src/modules/module-device-manager.c b/src/modules/module-device-manager.c
index 12eddec..1207824 100644
--- a/src/modules/module-device-manager.c
+++ b/src/modules/module-device-manager.c
@@ -1302,7 +1302,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
                     pa_xfree(device);
                 }
 
-                pa_hashmap_free(h, NULL, NULL);
+                pa_hashmap_free(h, NULL);
                 pa_log_error("Protocol error on reorder");
                 goto fail;
             }
@@ -1314,7 +1314,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
                     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.");
                 goto fail;
             }
@@ -1329,7 +1329,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
                     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)");
                 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))) {
             devices[idx++] = device;
         }
-        pa_hashmap_free(h, NULL, NULL);
+        pa_hashmap_free(h, NULL);
 
         /* Simple bubble sort */
         for (i = 0; i < n_devices; ++i) {
diff --git a/src/modules/module-filter-apply.c b/src/modules/module-filter-apply.c
index cd0cd8d..6826a0a 100644
--- a/src/modules/module-filter-apply.c
+++ b/src/modules/module-filter-apply.c
@@ -743,7 +743,7 @@ void pa__done(pa_module *m) {
             filter_free(f);
         }
 
-        pa_hashmap_free(u->filters, NULL, NULL);
+        pa_hashmap_free(u->filters, NULL);
     }
 
     pa_xfree(u);
diff --git a/src/modules/module-role-cork.c b/src/modules/module-role-cork.c
index 8f8b58d..77bac1e 100644
--- a/src/modules/module-role-cork.c
+++ b/src/modules/module-role-cork.c
@@ -311,7 +311,7 @@ void pa__done(pa_module *m) {
         pa_hook_slot_free(u->sink_input_move_finish_slot);
 
     if (u->cork_state)
-        pa_hashmap_free(u->cork_state, NULL, NULL);
+        pa_hashmap_free(u->cork_state, NULL);
 
     pa_xfree(u);
 
diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
index 1166a63..64bb241 100644
--- a/src/modules/module-stream-restore.c
+++ b/src/modules/module-stream-restore.c
@@ -2491,16 +2491,6 @@ fail:
     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) {
     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_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);
     }
diff --git a/src/modules/module-suspend-on-idle.c b/src/modules/module-suspend-on-idle.c
index f27dafd..02a6b91 100644
--- a/src/modules/module-suspend-on-idle.c
+++ b/src/modules/module-suspend-on-idle.c
@@ -474,7 +474,6 @@ fail:
 
 void pa__done(pa_module*m) {
     struct userdata *u;
-    struct device_info *d;
 
     pa_assert(m);
 
@@ -519,10 +518,7 @@ void pa__done(pa_module*m) {
     if (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)))
-        device_info_free(d);
-
-    pa_hashmap_free(u->device_infos, NULL, NULL);
+    pa_hashmap_free(u->device_infos, (pa_free_cb_t) device_info_free);
 
     pa_xfree(u);
 }
diff --git a/src/modules/module-systemd-login.c b/src/modules/module-systemd-login.c
index 024c1eb..2f24711 100644
--- a/src/modules/module-systemd-login.c
+++ b/src/modules/module-systemd-login.c
@@ -222,15 +222,8 @@ void pa__done(pa_module *m) {
         return;
 
     if (u->sessions) {
-        while ((session = pa_hashmap_steal_first(u->sessions)))
-            free_session(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);
+        pa_hashmap_free(u->sessions, (pa_free_cb_t) free_session);
+        pa_hashmap_free(u->previous_sessions, (pa_free_cb_t) free_session);
     }
 
     if (u->io)
diff --git a/src/modules/module-udev-detect.c b/src/modules/module-udev-detect.c
index 185c179..76cab90 100644
--- a/src/modules/module-udev-detect.c
+++ b/src/modules/module-udev-detect.c
@@ -817,14 +817,8 @@ void pa__done(pa_module *m) {
     if (u->inotify_fd >= 0)
         pa_close(u->inotify_fd);
 
-    if (u->devices) {
-        struct device *d;
-
-        while ((d = pa_hashmap_steal_first(u->devices)))
-            device_free(d);
-
-        pa_hashmap_free(u->devices, NULL, NULL);
-    }
+    if (u->devices)
+        pa_hashmap_free(u->devices, (pa_free_cb_t) device_free);
 
     pa_xfree(u);
 }
diff --git a/src/modules/module-zeroconf-discover.c b/src/modules/module-zeroconf-discover.c
index b17f6e5..4887510 100644
--- a/src/modules/module-zeroconf-discover.c
+++ b/src/modules/module-zeroconf-discover.c
@@ -426,7 +426,7 @@ void pa__done(pa_module*m) {
             tunnel_free(t);
         }
 
-        pa_hashmap_free(u->tunnels, NULL, NULL);
+        pa_hashmap_free(u->tunnels, NULL);
     }
 
     pa_xfree(u);
diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c
index 0c20cf6..c21ff3e 100644
--- a/src/modules/module-zeroconf-publish.c
+++ b/src/modules/module-zeroconf-publish.c
@@ -326,8 +326,10 @@ static int publish_service(struct service *s) {
 finish:
 
     /* Remove this service */
-    if (r < 0)
+    if (r < 0) {
+        pa_hashmap_remove(s->userdata->services, s->device);
         service_free(s);
+    }
 
     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) {
     pa_assert(s);
 
-    pa_hashmap_remove(s->userdata->services, s->device);
-
     if (s->entry_group) {
         pa_log_debug("Removing entry group for %s.", s->service_name);
         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_object_assert_ref(o);
 
-    if ((s = pa_hashmap_get(u->services, o)))
+    if ((s = pa_hashmap_remove(u->services, o)))
         service_free(s);
 
     return PA_HOOK_OK;
@@ -661,14 +661,8 @@ void pa__done(pa_module*m) {
     if (!(u = m->userdata))
         return;
 
-    if (u->services) {
-        struct service *s;
-
-        while ((s = pa_hashmap_first(u->services)))
-            service_free(s);
-
-        pa_hashmap_free(u->services, NULL, NULL);
-    }
+    if (u->services)
+        pa_hashmap_free(u->services, (pa_free_cb_t) service_free);
 
     if (u->sink_new_slot)
         pa_hook_slot_free(u->sink_new_slot);
diff --git a/src/modules/raop/module-raop-discover.c b/src/modules/raop/module-raop-discover.c
index 7499f63..3db2c0e 100644
--- a/src/modules/raop/module-raop-discover.c
+++ b/src/modules/raop/module-raop-discover.c
@@ -381,7 +381,7 @@ void pa__done(pa_module*m) {
             tunnel_free(t);
         }
 
-        pa_hashmap_free(u->tunnels, NULL, NULL);
+        pa_hashmap_free(u->tunnels, NULL);
     }
 
     pa_xfree(u);
diff --git a/src/modules/rtp/headerlist.c b/src/modules/rtp/headerlist.c
index 0fef835..3007518 100644
--- a/src/modules/rtp/headerlist.c
+++ b/src/modules/rtp/headerlist.c
@@ -56,12 +56,7 @@ pa_headerlist* pa_headerlist_new(void) {
 }
 
 void pa_headerlist_free(pa_headerlist* p) {
-    struct header *hdr;
-
-    while ((hdr = pa_hashmap_steal_first(MAKE_HASHMAP(p))))
-        header_free(hdr);
-
-    pa_hashmap_free(MAKE_HASHMAP(p), NULL, NULL);
+    pa_hashmap_free(MAKE_HASHMAP(p), (pa_free_cb_t) header_free);
 }
 
 int pa_headerlist_puts(pa_headerlist *p, const char *key, const char *value) {
diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c
index 3e9250c..45d03f5 100644
--- a/src/modules/rtp/module-rtp-recv.c
+++ b/src/modules/rtp/module-rtp-recv.c
@@ -186,6 +186,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);
 }
 
@@ -606,7 +607,6 @@ static void session_free(struct session *s) {
     PA_LLIST_REMOVE(struct session, s->userdata->sessions, s);
     pa_assert(s->userdata->n_sessions >= 1);
     s->userdata->n_sessions--;
-    pa_hashmap_remove(s->userdata->by_origin, s->sdp_info.origin);
 
     pa_memblockq_free(s->memblockq);
     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 ((s = pa_hashmap_get(u->by_origin, info.origin)))
+        if ((s = pa_hashmap_remove(u->by_origin, info.origin)))
             session_free(s);
 
         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);
 
-        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);
+        }
     }
 
     /* Restart timer */
@@ -753,7 +755,6 @@ fail:
 
 void pa__done(pa_module*m) {
     struct userdata *u;
-    struct session *s;
 
     pa_assert(m);
 
@@ -768,12 +769,8 @@ void pa__done(pa_module*m) {
 
     pa_sap_context_destroy(&u->sap_context);
 
-    if (u->by_origin) {
-        while ((s = pa_hashmap_first(u->by_origin)))
-            session_free(s);
-
-        pa_hashmap_free(u->by_origin, NULL, NULL);
-    }
+    if (u->by_origin)
+        pa_hashmap_free(u->by_origin, (pa_free_cb_t) session_free);
 
     pa_xfree(u->sink_name);
     pa_xfree(u);
diff --git a/src/pulse/context.c b/src/pulse/context.c
index 4618635..7176412 100644
--- a/src/pulse/context.c
+++ b/src/pulse/context.c
@@ -241,9 +241,9 @@ static void context_free(pa_context *c) {
 #endif
 
     if (c->record_streams)
-        pa_hashmap_free(c->record_streams, NULL, NULL);
+        pa_hashmap_free(c->record_streams, NULL);
     if (c->playback_streams)
-        pa_hashmap_free(c->playback_streams, NULL, NULL);
+        pa_hashmap_free(c->playback_streams, NULL);
 
     if (c->mempool)
         pa_mempool_free(c->mempool);
diff --git a/src/pulse/proplist.c b/src/pulse/proplist.c
index 2c197bc..33b150c 100644
--- a/src/pulse/proplist.c
+++ b/src/pulse/proplist.c
@@ -70,8 +70,7 @@ pa_proplist* pa_proplist_new(void) {
 void pa_proplist_free(pa_proplist* p) {
     pa_assert(p);
 
-    pa_proplist_clear(p);
-    pa_hashmap_free(MAKE_HASHMAP(p), NULL, NULL);
+    pa_hashmap_free(MAKE_HASHMAP(p), (pa_free_cb_t) property_free);
 }
 
 /** Will accept only valid UTF-8 */
diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
index afabc95..560e36e 100644
--- a/src/pulsecore/card.c
+++ b/src/pulsecore/card.c
@@ -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) {
     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->description);
@@ -126,14 +125,8 @@ void pa_card_new_data_done(pa_card_new_data *data) {
 
     pa_proplist_free(data->proplist);
 
-    if (data->profiles) {
-        pa_card_profile *c;
-
-        while ((c = pa_hashmap_steal_first(data->profiles)))
-            pa_card_profile_free(c);
-
-        pa_hashmap_free(data->profiles, NULL, NULL);
-    }
+    if (data->profiles)
+        pa_hashmap_free(data->profiles, (pa_free_cb_t) pa_card_profile_free);
 
     if (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);
 
-    if (c->profiles) {
-        pa_card_profile *p;
-
-        while ((p = pa_hashmap_steal_first(c->profiles))) {
-            p->card = NULL;
-            pa_card_profile_free(p);
-        }
-
-        pa_hashmap_free(c->profiles, NULL, NULL);
-    }
+    if (c->profiles)
+        pa_hashmap_free(c->profiles, (pa_free_cb_t) pa_card_profile_free);
 
     pa_proplist_free(c->proplist);
     pa_xfree(c->driver);
diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c
index e4f9140..37f3fae 100644
--- a/src/pulsecore/core.c
+++ b/src/pulsecore/core.c
@@ -194,10 +194,10 @@ static void core_free(pa_object *o) {
     pa_idxset_free(c->sink_inputs, NULL, NULL);
 
     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_hashmap_free(c->shared, NULL, NULL);
+    pa_hashmap_free(c->shared, NULL);
 
     pa_subscription_free_all(c);
 
diff --git a/src/pulsecore/database-simple.c b/src/pulsecore/database-simple.c
index db68158..5dd3ac9 100644
--- a/src/pulsecore/database-simple.c
+++ b/src/pulsecore/database-simple.c
@@ -264,10 +264,9 @@ void pa_database_close(pa_database *database) {
     pa_assert(db);
 
     pa_database_sync(database);
-    pa_database_clear(database);
     pa_xfree(db->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);
 }
 
diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 6d787ac..5c7a5bb 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -56,8 +56,10 @@ static void device_port_free(pa_object *o) {
 
     if (p->proplist)
         pa_proplist_free(p->proplist);
+
     if (p->profiles)
-        pa_hashmap_free(p->profiles, NULL, NULL);
+        pa_hashmap_free(p->profiles, NULL);
+
     pa_xfree(p->name);
     pa_xfree(p->description);
     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) {
-    pa_device_port *p;
-
     pa_assert(h);
 
-    while ((p = pa_hashmap_steal_first(h)))
-        pa_device_port_unref(p);
-
-    pa_hashmap_free(h, NULL, NULL);
+    pa_hashmap_free(h, (pa_free_cb_t) pa_device_port_unref);
 }
 
 void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {
diff --git a/src/pulsecore/hashmap.c b/src/pulsecore/hashmap.c
index e368512..cfd08b7 100644
--- a/src/pulsecore/hashmap.c
+++ b/src/pulsecore/hashmap.c
@@ -101,7 +101,7 @@ static void remove_entry(pa_hashmap *h, struct hashmap_entry *e) {
     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);
 
     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);
 
         if (free_cb)
-            free_cb(data, userdata);
+            free_cb(data);
     }
 
     pa_xfree(h);
diff --git a/src/pulsecore/hashmap.h b/src/pulsecore/hashmap.h
index ac2092a..8d892b8 100644
--- a/src/pulsecore/hashmap.h
+++ b/src/pulsecore/hashmap.h
@@ -22,6 +22,8 @@
   USA.
 ***/
 
+#include <pulse/def.h>
+
 #include <pulsecore/idxset.h>
 
 /* 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);
 
 /* 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 */
 int pa_hashmap_put(pa_hashmap *h, const void *key, void *value);
diff --git a/src/pulsecore/memblock.c b/src/pulsecore/memblock.c
index ea7b274..5b77df3 100644
--- a/src/pulsecore/memblock.c
+++ b/src/pulsecore/memblock.c
@@ -964,8 +964,8 @@ void pa_memimport_free(pa_memimport *i) {
 
     pa_mutex_unlock(i->pool->mutex);
 
-    pa_hashmap_free(i->blocks, NULL, NULL);
-    pa_hashmap_free(i->segments, NULL, NULL);
+    pa_hashmap_free(i->blocks, NULL);
+    pa_hashmap_free(i->segments, NULL);
 
     pa_mutex_free(i->mutex);
 
diff --git a/src/pulsecore/modargs.c b/src/pulsecore/modargs.c
index 0abc243..d48a2c8 100644
--- a/src/pulsecore/modargs.c
+++ b/src/pulsecore/modargs.c
@@ -247,7 +247,7 @@ fail:
     return NULL;
 }
 
-static void free_func(void *p, void*userdata) {
+static void free_func(void *p) {
     struct entry *e = p;
     pa_assert(e);
 
@@ -259,8 +259,8 @@ static void free_func(void *p, void*userdata) {
 void pa_modargs_free(pa_modargs*ma) {
     pa_assert(ma);
 
-    pa_hashmap_free(ma->raw, free_func, NULL);
-    pa_hashmap_free(ma->unescaped, free_func, NULL);
+    pa_hashmap_free(ma->raw, free_func);
+    pa_hashmap_free(ma->unescaped, free_func);
     pa_xfree(ma);
 }
 
diff --git a/src/pulsecore/mutex-win32.c b/src/pulsecore/mutex-win32.c
index f4652a9..e70f230 100644
--- a/src/pulsecore/mutex-win32.c
+++ b/src/pulsecore/mutex-win32.c
@@ -80,7 +80,7 @@ pa_cond *pa_cond_new(void) {
 void pa_cond_free(pa_cond *c) {
     assert(c);
 
-    pa_hashmap_free(c->wait_events, NULL, NULL);
+    pa_hashmap_free(c->wait_events, NULL);
     pa_xfree(c);
 }
 
diff --git a/src/pulsecore/protocol-dbus.c b/src/pulsecore/protocol-dbus.c
index c82ea4a..dab4678 100644
--- a/src/pulsecore/protocol-dbus.c
+++ b/src/pulsecore/protocol-dbus.c
@@ -169,8 +169,8 @@ void pa_dbus_protocol_unref(pa_dbus_protocol *p) {
     pa_assert(pa_hashmap_isempty(p->connections));
     pa_assert(pa_idxset_isempty(p->extensions));
 
-    pa_hashmap_free(p->objects, NULL, NULL);
-    pa_hashmap_free(p->connections, NULL, NULL);
+    pa_hashmap_free(p->objects, NULL);
+    pa_hashmap_free(p->connections, NULL);
     pa_idxset_free(p->extensions, NULL, NULL);
 
     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));
 }
 
-static void method_handler_free_cb(void *p, void *userdata) {
-    pa_dbus_method_handler *h = p;
+static void method_handler_free(pa_dbus_method_handler *h) {
     unsigned i;
 
     pa_assert(h);
@@ -807,15 +806,7 @@ static void method_handler_free_cb(void *p, void *userdata) {
     pa_xfree(h);
 }
 
-static void method_signature_free_cb(void *p, void *userdata) {
-    pa_assert(p);
-
-    pa_xfree(p);
-}
-
-static void property_handler_free_cb(void *p, void *userdata) {
-    pa_dbus_property_handler *h = p;
-
+static void property_handler_free(pa_dbus_property_handler *h) {
     pa_assert(h);
 
     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_xfree(iface_entry->name);
-    pa_hashmap_free(iface_entry->method_signatures, method_signature_free_cb, NULL);
-    pa_hashmap_free(iface_entry->method_handlers, method_handler_free_cb, NULL);
-    pa_hashmap_free(iface_entry->property_handlers, property_handler_free_cb, NULL);
+    pa_hashmap_free(iface_entry->method_signatures, pa_xfree);
+    pa_hashmap_free(iface_entry->method_handlers, (pa_free_cb_t) method_handler_free);
+    pa_hashmap_free(iface_entry->property_handlers, (pa_free_cb_t) property_handler_free);
 
     for (i = 0; i < iface_entry->n_signals; ++i) {
         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_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);
     }
@@ -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) {
     struct connection_entry *conn_entry = NULL;
-    struct signal_paths_entry *signal_paths_entry = NULL;
     char *object_path = NULL;
 
     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);
 
-    while ((signal_paths_entry = pa_hashmap_steal_first(conn_entry->listening_signals)))
-        signal_paths_entry_free(signal_paths_entry);
-
-    pa_hashmap_free(conn_entry->listening_signals, NULL, NULL);
+    pa_hashmap_free(conn_entry->listening_signals, (pa_free_cb_t) signal_paths_entry_free);
     pa_xfree(conn_entry);
 
     return 0;
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index 88808bf..6a9379e 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -5100,7 +5100,7 @@ void pa_native_protocol_unref(pa_native_protocol *p) {
     for (h = 0; h < PA_NATIVE_HOOK_MAX; 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);
 
diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index ae89aed..7e6efe0 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -74,10 +74,6 @@ static void volume_factor_entry_free(struct volume_factor_entry *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) {
     struct volume_factor_entry *entry;
     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);
 
     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)
-        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);
 }
@@ -745,12 +741,13 @@ static void sink_input_free(pa_object *o) {
         pa_idxset_free(i->direct_outputs, NULL, NULL);
 
     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)
-        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)
-        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);
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index a8a91d6..5dd168c 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -714,7 +714,6 @@ void pa_sink_unlink(pa_sink* s) {
 /* Called from main context */
 static void sink_free(pa_object *o) {
     pa_sink *s = PA_SINK(o);
-    pa_sink_input *i;
 
     pa_assert(s);
     pa_assert_ctl_context();
@@ -731,11 +730,7 @@ static void sink_free(pa_object *o) {
     }
 
     pa_idxset_free(s->inputs, NULL, NULL);
-
-    while ((i = pa_hashmap_steal_first(s->thread_info.inputs)))
-        pa_sink_input_unref(i);
-
-    pa_hashmap_free(s->thread_info.inputs, NULL, NULL);
+    pa_hashmap_free(s->thread_info.inputs, (pa_free_cb_t) pa_sink_input_unref);
 
     if (s->silence.memblock)
         pa_memblock_unref(s->silence.memblock);
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 8c16606..9915cea 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -648,7 +648,6 @@ void pa_source_unlink(pa_source *s) {
 
 /* Called from main context */
 static void source_free(pa_object *o) {
-    pa_source_output *so;
     pa_source *s = PA_SOURCE(o);
 
     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_idxset_free(s->outputs, NULL, NULL);
-
-    while ((so = pa_hashmap_steal_first(s->thread_info.outputs)))
-        pa_source_output_unref(so);
-
-    pa_hashmap_free(s->thread_info.outputs, NULL, NULL);
+    pa_hashmap_free(s->thread_info.outputs, (pa_free_cb_t) pa_source_output_unref);
 
     if (s->silence.memblock)
         pa_memblock_unref(s->silence.memblock);
-- 
1.7.10.4



More information about the pulseaudio-discuss mailing list