[pulseaudio-discuss] [PATCH] hashmap: Add the ability to free keys

Arun Raghavan arun.raghavan at collabora.co.uk
Fri Sep 13 23:34:00 PDT 2013


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.
---
 src/modules/alsa/alsa-mixer.c                      |  28 +++---
 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 |   4 +-
 src/modules/dbus/iface-card.c                      |   9 +-
 src/modules/dbus/iface-core.c                      |  48 +++++-----
 src/modules/dbus/iface-device.c                    |   8 +-
 src/modules/gconf/module-gconf.c                   |   4 +-
 src/modules/macosx/module-bonjour-publish.c        |   2 +-
 src/modules/module-augment-properties.c            |   4 +-
 src/modules/module-card-restore.c                  |  18 ++--
 src/modules/module-console-kit.c                   |   4 +-
 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                |   4 +-
 src/modules/module-suspend-on-idle.c               |   4 +-
 src/modules/module-systemd-login.c                 |  10 +-
 src/modules/module-udev-detect.c                   |   4 +-
 src/modules/module-zeroconf-discover.c             |   2 +-
 src/modules/module-zeroconf-publish.c              |   4 +-
 src/modules/raop/module-raop-discover.c            |   2 +-
 src/modules/rtp/headerlist.c                       |   4 +-
 src/modules/rtp/module-rtp-recv.c                  |   4 +-
 src/pulse/context.c                                |   4 +-
 src/pulse/proplist.c                               |   6 +-
 src/pulsecore/card.c                               |  12 +--
 src/pulsecore/core.c                               |   4 +-
 src/pulsecore/database-simple.c                    |   6 +-
 src/pulsecore/device-port.c                        |   2 +-
 src/pulsecore/hashmap.c                            |  29 ++++--
 src/pulsecore/hashmap.h                            |  14 ++-
 src/pulsecore/memblock.c                           |   4 +-
 src/pulsecore/modargs.c                            |  26 +++---
 src/pulsecore/mutex-win32.c                        |   2 +-
 src/pulsecore/protocol-dbus.c                      | 101 +++++++++++----------
 src/pulsecore/protocol-native.c                    |   2 +-
 src/pulsecore/sink-input.c                         |  16 ++--
 src/pulsecore/sink.c                               |  11 ++-
 src/pulsecore/source.c                             |  11 ++-
 41 files changed, 232 insertions(+), 205 deletions(-)

diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 545ae9f..8c95b1c 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);
+        pa_hashmap_free(ps->paths);
 
     pa_xfree(ps);
 }
@@ -3337,19 +3337,19 @@ void pa_alsa_profile_set_free(pa_alsa_profile_set *ps) {
     pa_assert(ps);
 
     if (ps->input_paths)
-        pa_hashmap_free(ps->input_paths, (pa_free_cb_t) pa_alsa_path_free);
+        pa_hashmap_free(ps->input_paths);
 
     if (ps->output_paths)
-        pa_hashmap_free(ps->output_paths, (pa_free_cb_t) pa_alsa_path_free);
+        pa_hashmap_free(ps->output_paths);
 
     if (ps->profiles)
-        pa_hashmap_free(ps->profiles, (pa_free_cb_t) profile_free);
+        pa_hashmap_free(ps->profiles);
 
     if (ps->mappings)
-        pa_hashmap_free(ps->mappings, (pa_free_cb_t) mapping_free);
+        pa_hashmap_free(ps->mappings);
 
     if (ps->decibel_fixes)
-        pa_hashmap_free(ps->decibel_fixes, (pa_free_cb_t) decibel_fix_free);
+        pa_hashmap_free(ps->decibel_fixes);
 
     pa_xfree(ps);
 }
@@ -3776,7 +3776,7 @@ static void mapping_paths_probe(pa_alsa_mapping *m, pa_alsa_profile *profile,
     mixer_handle = pa_alsa_open_mixer_for_pcm(pcm_handle, NULL, &hctl_handle);
     if (!mixer_handle || !hctl_handle) {
          /* Cannot open mixer, remove all entries */
-        pa_hashmap_remove_all(ps->paths, NULL);
+        pa_hashmap_remove_all(ps->paths);
         return;
     }
 
@@ -4167,11 +4167,11 @@ pa_alsa_profile_set* pa_alsa_profile_set_new(const char *fname, const pa_channel
     };
 
     ps = pa_xnew0(pa_alsa_profile_set, 1);
-    ps->mappings = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    ps->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    ps->decibel_fixes = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    ps->input_paths = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    ps->output_paths = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    ps->mappings = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) mapping_free);
+    ps->profiles = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) profile_free);
+    ps->decibel_fixes = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) decibel_fix_free);
+    ps->input_paths = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_alsa_path_free);
+    ps->output_paths = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_alsa_path_free);
 
     items[0].data = &ps->auto_profiles;
 
@@ -4420,8 +4420,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);
-    pa_hashmap_free(broken_outputs, NULL);
+    pa_hashmap_free(broken_inputs);
+    pa_hashmap_free(broken_outputs);
 
     ps->probed = true;
 }
diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c
index f4fb77f..96e88e5 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -820,7 +820,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);
+        pa_hashmap_free(u->jacks);
 
     if (u->card && u->card->sinks)
         pa_idxset_remove_all(u->card->sinks, (pa_free_cb_t) pa_alsa_sink_free);
diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index dd280cb..892e5fa 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -2109,12 +2109,12 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
 
     if (y->devices) {
         remove_all_devices(y);
-        pa_hashmap_free(y->devices, NULL);
+        pa_hashmap_free(y->devices);
     }
 
     if (y->transports) {
         pa_assert(pa_hashmap_isempty(y->transports));
-        pa_hashmap_free(y->transports, NULL);
+        pa_hashmap_free(y->transports);
     }
 
     if (y->connection) {
diff --git a/src/modules/bluetooth/module-bluetooth-discover.c b/src/modules/bluetooth/module-bluetooth-discover.c
index cbd56cc..4ebf298 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);
+        pa_hashmap_free(u->hashmap);
     }
 
     if (u->modargs)
diff --git a/src/modules/bluetooth/module-bluetooth-proximity.c b/src/modules/bluetooth/module-bluetooth-proximity.c
index c4e6ca6..1110ceb 100644
--- a/src/modules/bluetooth/module-bluetooth-proximity.c
+++ b/src/modules/bluetooth/module-bluetooth-proximity.c
@@ -393,7 +393,7 @@ int pa__init(pa_module*m) {
     u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
     u->hci = pa_xstrdup(pa_modargs_get_value(ma, "hci", DEFAULT_HCI));
     u->hci_path = pa_sprintf_malloc("/org/bluez/%s", u->hci);
-    u->bondings = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    u->bondings = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) bonding_free);
 
     if (!(u->dbus_connection = pa_dbus_bus_get(m->core, DBUS_BUS_SYSTEM, &e))) {
         pa_log("Failed to get D-Bus connection: %s", e.message);
@@ -466,7 +466,7 @@ void pa__done(pa_module*m) {
         return;
 
     if (u->bondings)
-        pa_hashmap_free(u->bondings, (pa_free_cb_t) bonding_free);
+        pa_hashmap_free(u->bondings);
 
     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 19dd4ed..da98043 100644
--- a/src/modules/dbus/iface-card.c
+++ b/src/modules/dbus/iface-card.c
@@ -495,7 +495,7 @@ static pa_hook_result_t card_profile_added_cb(void *hook_data, void *call_data,
         return PA_HOOK_OK;
 
     p = pa_dbusiface_card_profile_new(c, core, profile, c->next_profile_index++);
-    pa_assert_se(pa_hashmap_put(c->profiles, pa_dbusiface_card_profile_get_name(p), p) >= 0);
+    pa_assert_se(pa_hashmap_put(c->profiles, (char *) pa_dbusiface_card_profile_get_name(p), p) >= 0);
 
     /* Send D-Bus signal */
     object_path = pa_dbusiface_card_profile_get_path(p);
@@ -523,7 +523,8 @@ pa_dbusiface_card *pa_dbusiface_card_new(pa_dbusiface_core *core, pa_card *card)
     c->core = core;
     c->card = card;
     c->path = pa_sprintf_malloc("%s/%s%u", PA_DBUS_CORE_OBJECT_PATH, OBJECT_NAME, card->index);
-    c->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    c->profiles = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL,
+                                      (pa_free_cb_t) pa_dbusiface_card_profile_free);
     c->next_profile_index = 0;
     c->active_profile = card->active_profile;
     c->proplist = pa_proplist_copy(card->proplist);
@@ -532,7 +533,7 @@ pa_dbusiface_card *pa_dbusiface_card_new(pa_dbusiface_core *core, pa_card *card)
 
     PA_HASHMAP_FOREACH(profile, card->profiles, state) {
         pa_dbusiface_card_profile *p = pa_dbusiface_card_profile_new(c, card->core, profile, c->next_profile_index++);
-        pa_hashmap_put(c->profiles, pa_dbusiface_card_profile_get_name(p), p);
+        pa_hashmap_put(c->profiles, (char *) pa_dbusiface_card_profile_get_name(p), p);
     }
 
     pa_assert_se(pa_dbus_protocol_add_interface(c->dbus_protocol, c->path, &card_interface_info, c) >= 0);
@@ -550,7 +551,7 @@ void pa_dbusiface_card_free(pa_dbusiface_card *c) {
 
     pa_hook_slot_free(c->card_profile_added_slot);
 
-    pa_hashmap_free(c->profiles, (pa_free_cb_t) pa_dbusiface_card_profile_free);
+    pa_hashmap_free(c->profiles);
     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 edc22ab..22dae32 100644
--- a/src/modules/dbus/iface-core.c
+++ b/src/modules/dbus/iface-core.c
@@ -1870,7 +1870,7 @@ static pa_hook_result_t sink_put_cb(void *hook_data, void *call_data, void *slot
     object_path = pa_dbusiface_device_get_path(d);
 
     pa_assert_se(pa_hashmap_put(c->sinks_by_index, PA_UINT32_TO_PTR(s->index), d) >= 0);
-    pa_assert_se(pa_hashmap_put(c->sinks_by_path, object_path, d) >= 0);
+    pa_assert_se(pa_hashmap_put(c->sinks_by_path, (char *) object_path, d) >= 0);
 
     pa_assert_se(signal_msg = dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH,
                                                       PA_DBUS_CORE_INTERFACE,
@@ -1924,7 +1924,7 @@ static pa_hook_result_t source_put_cb(void *hook_data, void *call_data, void *sl
     object_path = pa_dbusiface_device_get_path(d);
 
     pa_assert_se(pa_hashmap_put(c->sources_by_index, PA_UINT32_TO_PTR(s->index), d) >= 0);
-    pa_assert_se(pa_hashmap_put(c->sources_by_path, object_path, d) >= 0);
+    pa_assert_se(pa_hashmap_put(c->sources_by_path, (char *) object_path, d) >= 0);
 
     pa_assert_se((signal_msg = dbus_message_new_signal(PA_DBUS_CORE_OBJECT_PATH,
                                                        PA_DBUS_CORE_INTERFACE,
@@ -2021,16 +2021,20 @@ pa_dbusiface_core *pa_dbusiface_core_new(pa_core *core) {
     c->core = core;
     c->subscription = pa_subscription_new(core, PA_SUBSCRIPTION_MASK_ALL, subscription_cb, c);
     c->dbus_protocol = pa_dbus_protocol_get(core);
-    c->cards = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
-    c->sinks_by_index = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+    c->cards = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL, (pa_free_cb_t) pa_dbusiface_card_free);
+    c->sinks_by_index = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL,
+                                            (pa_free_cb_t) pa_dbusiface_device_free);
     c->sinks_by_path = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    c->sources_by_index = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+    c->sources_by_index = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL,
+                                              (pa_free_cb_t) pa_dbusiface_device_free);
     c->sources_by_path = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    c->playback_streams = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
-    c->record_streams = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
-    c->samples = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
-    c->modules = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
-    c->clients = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+    c->playback_streams = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL,
+                                              (pa_free_cb_t) pa_dbusiface_stream_free);
+    c->record_streams = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL,
+                                            (pa_free_cb_t) pa_dbusiface_stream_free);
+    c->samples = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL, (pa_free_cb_t) pa_dbusiface_sample_free);
+    c->modules = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL, (pa_free_cb_t) pa_dbusiface_module_free);
+    c->clients = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL, (pa_free_cb_t) pa_dbusiface_client_free);
     c->fallback_sink = pa_namereg_get_default_sink(core);
     c->fallback_source = pa_namereg_get_default_source(core);
     c->sink_put_slot = pa_hook_connect(&core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_NORMAL, sink_put_cb, c);
@@ -2060,13 +2064,13 @@ pa_dbusiface_core *pa_dbusiface_core_new(pa_core *core) {
     PA_IDXSET_FOREACH(sink, core->sinks, idx) {
         device = pa_dbusiface_device_new_sink(c, sink);
         pa_hashmap_put(c->sinks_by_index, PA_UINT32_TO_PTR(idx), device);
-        pa_hashmap_put(c->sinks_by_path, pa_dbusiface_device_get_path(device), device);
+        pa_hashmap_put(c->sinks_by_path, (char *) pa_dbusiface_device_get_path(device), device);
     }
 
     PA_IDXSET_FOREACH(source, core->sources, idx) {
         device = pa_dbusiface_device_new_source(c, source);
         pa_hashmap_put(c->sources_by_index, PA_UINT32_TO_PTR(idx), device);
-        pa_hashmap_put(c->sources_by_path, pa_dbusiface_device_get_path(device), device);
+        pa_hashmap_put(c->sources_by_path, (char *) pa_dbusiface_device_get_path(device), device);
     }
 
     PA_IDXSET_FOREACH(sink_input, core->sink_inputs, idx)
@@ -2097,16 +2101,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, (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_hashmap_free(c->cards);
+    pa_hashmap_free(c->sinks_by_path);
+    pa_hashmap_free(c->sinks_by_index);
+    pa_hashmap_free(c->sources_by_path);
+    pa_hashmap_free(c->sources_by_index);
+    pa_hashmap_free(c->playback_streams);
+    pa_hashmap_free(c->record_streams);
+    pa_hashmap_free(c->samples);
+    pa_hashmap_free(c->modules);
+    pa_hashmap_free(c->clients);
     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 4af0333..34b370b 100644
--- a/src/modules/dbus/iface-device.c
+++ b/src/modules/dbus/iface-device.c
@@ -1214,7 +1214,7 @@ pa_dbusiface_device *pa_dbusiface_device_new_sink(pa_dbusiface_core *core, pa_si
     d->volume = *pa_sink_get_volume(sink, false);
     d->mute = pa_sink_get_mute(sink, false);
     d->sink_state = pa_sink_get_state(sink);
-    d->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    d->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_dbusiface_device_port_free);
     d->next_port_index = 0;
     d->active_port = sink->active_port;
     d->proplist = pa_proplist_copy(sink->proplist);
@@ -1223,7 +1223,7 @@ pa_dbusiface_device *pa_dbusiface_device_new_sink(pa_dbusiface_core *core, pa_si
 
     PA_HASHMAP_FOREACH(port, sink->ports, state) {
         pa_dbusiface_device_port *p = pa_dbusiface_device_port_new(d, sink->core, port, d->next_port_index++);
-        pa_hashmap_put(d->ports, pa_dbusiface_device_port_get_name(p), p);
+        pa_hashmap_put(d->ports, (char *) pa_dbusiface_device_port_get_name(p), p);
     }
 
     pa_assert_se(pa_dbus_protocol_add_interface(d->dbus_protocol, d->path, &device_interface_info, d) >= 0);
@@ -1257,7 +1257,7 @@ pa_dbusiface_device *pa_dbusiface_device_new_source(pa_dbusiface_core *core, pa_
 
     PA_HASHMAP_FOREACH(port, source->ports, state) {
         pa_dbusiface_device_port *p = pa_dbusiface_device_port_new(d, source->core, port, d->next_port_index++);
-        pa_hashmap_put(d->ports, pa_dbusiface_device_port_get_name(p), p);
+        pa_hashmap_put(d->ports, (char *) pa_dbusiface_device_port_get_name(p), p);
     }
 
     pa_assert_se(pa_dbus_protocol_add_interface(d->dbus_protocol, d->path, &device_interface_info, d) >= 0);
@@ -1279,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, (pa_free_cb_t) pa_dbusiface_device_port_free);
+    pa_hashmap_free(d->ports);
     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 448fde5..dee15af 100644
--- a/src/modules/gconf/module-gconf.c
+++ b/src/modules/gconf/module-gconf.c
@@ -336,7 +336,7 @@ int pa__init(pa_module*m) {
     u->core = m->core;
     u->module = m;
     m->userdata = u;
-    u->module_infos = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    u->module_infos = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) module_info_free);
     u->pid = (pid_t) -1;
     u->fd = -1;
     u->fd_type = 0;
@@ -401,7 +401,7 @@ void pa__done(pa_module*m) {
         pa_close(u->fd);
 
     if (u->module_infos)
-        pa_hashmap_free(u->module_infos, (pa_free_cb_t) module_info_free);
+        pa_hashmap_free(u->module_infos);
 
     pa_xfree(u);
 }
diff --git a/src/modules/macosx/module-bonjour-publish.c b/src/modules/macosx/module-bonjour-publish.c
index 26081ec..f0b8b82 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);
+        pa_hashmap_free(u->services);
 
     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 fcc3462..9d42a2b 100644
--- a/src/modules/module-augment-properties.c
+++ b/src/modules/module-augment-properties.c
@@ -317,7 +317,7 @@ int pa__init(pa_module *m) {
 
     m->userdata = u = pa_xnew(struct userdata, 1);
 
-    u->cache = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    u->cache = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) rule_free);
     u->client_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CLIENT_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) client_new_cb, u);
     u->client_proplist_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CLIENT_PROPLIST_CHANGED], PA_HOOK_EARLY, (pa_hook_cb_t) client_proplist_changed_cb, u);
 
@@ -348,7 +348,7 @@ void pa__done(pa_module *m) {
         pa_hook_slot_free(u->client_proplist_changed_slot);
 
     if (u->cache)
-        pa_hashmap_free(u->cache, (pa_free_cb_t) rule_free);
+        pa_hashmap_free(u->cache);
 
     pa_xfree(u);
 }
diff --git a/src/modules/module-card-restore.c b/src/modules/module-card-restore.c
index 024d94a..19b6c25 100644
--- a/src/modules/module-card-restore.c
+++ b/src/modules/module-card-restore.c
@@ -107,10 +107,17 @@ static void trigger_save(struct userdata *u) {
     u->save_time_event = pa_core_rttime_new(u->core, pa_rtclock_now() + SAVE_INTERVAL, save_time_callback, u);
 }
 
+static void port_info_free(struct port_info *p_info) {
+    pa_assert(p_info);
+
+    pa_xfree(p_info->name);
+    pa_xfree(p_info);
+}
+
 static struct entry* entry_new(void) {
     struct entry *r = pa_xnew0(struct entry, 1);
     r->version = ENTRY_VERSION;
-    r->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    r->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) port_info_free);
     return r;
 }
 
@@ -127,18 +134,11 @@ static struct port_info *port_info_new(pa_device_port *port) {
     return p_info;
 }
 
-static void port_info_free(struct port_info *p_info) {
-    pa_assert(p_info);
-
-    pa_xfree(p_info->name);
-    pa_xfree(p_info);
-}
-
 static void entry_free(struct entry* e) {
     pa_assert(e);
 
     pa_xfree(e->profile);
-    pa_hashmap_free(e->ports, (pa_free_cb_t) port_info_free);
+    pa_hashmap_free(e->ports);
 
     pa_xfree(e);
 }
diff --git a/src/modules/module-console-kit.c b/src/modules/module-console-kit.c
index 007d23b..2ea2d67 100644
--- a/src/modules/module-console-kit.c
+++ b/src/modules/module-console-kit.c
@@ -303,7 +303,7 @@ int pa__init(pa_module*m) {
     u->core = m->core;
     u->module = m;
     u->connection = connection;
-    u->sessions = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    u->sessions = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) free_session);
 
     if (!dbus_connection_add_filter(pa_dbus_connection_get(connection), filter_cb, u, NULL)) {
         pa_log_error("Failed to add filter function");
@@ -346,7 +346,7 @@ void pa__done(pa_module *m) {
         return;
 
     if (u->sessions)
-        pa_hashmap_free(u->sessions, (pa_free_cb_t) free_session);
+        pa_hashmap_free(u->sessions);
 
     if (u->connection) {
         pa_dbus_remove_matches(
diff --git a/src/modules/module-device-manager.c b/src/modules/module-device-manager.c
index 6ae9cee..9df3d8e 100644
--- a/src/modules/module-device-manager.c
+++ b/src/modules/module-device-manager.c
@@ -1311,7 +1311,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
                     pa_xfree(device);
                 }
 
-                pa_hashmap_free(h, NULL);
+                pa_hashmap_free(h);
                 pa_log_error("Protocol error on reorder");
                 goto fail;
             }
@@ -1323,7 +1323,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
                     pa_xfree(device);
                 }
 
-                pa_hashmap_free(h, NULL);
+                pa_hashmap_free(h);
                 pa_log_error("Client specified an unknown device in it's reorder list.");
                 goto fail;
             }
@@ -1338,7 +1338,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
                     pa_xfree(device);
                 }
 
-                pa_hashmap_free(h, NULL);
+                pa_hashmap_free(h);
                 pa_log_error("Attempted to reorder mixed devices (sinks and sources)");
                 goto fail;
             }
@@ -1411,7 +1411,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);
+        pa_hashmap_free(h);
 
         /* 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 05d4284..8345894 100644
--- a/src/modules/module-filter-apply.c
+++ b/src/modules/module-filter-apply.c
@@ -747,7 +747,7 @@ void pa__done(pa_module *m) {
             filter_free(f);
         }
 
-        pa_hashmap_free(u->filters, NULL);
+        pa_hashmap_free(u->filters);
     }
 
     pa_xfree(u);
diff --git a/src/modules/module-role-cork.c b/src/modules/module-role-cork.c
index 9906d2e..6573cd6 100644
--- a/src/modules/module-role-cork.c
+++ b/src/modules/module-role-cork.c
@@ -304,7 +304,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);
+        pa_hashmap_free(u->cork_state);
 
     pa_xfree(u);
 
diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
index 735dcde..7eb79ab 100644
--- a/src/modules/module-stream-restore.c
+++ b/src/modules/module-stream-restore.c
@@ -2451,7 +2451,7 @@ int pa__init(pa_module*m) {
 
 #ifdef HAVE_DBUS
     u->dbus_protocol = pa_dbus_protocol_get(u->core);
-    u->dbus_entries = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    u->dbus_entries = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) dbus_entry_free);
 
     pa_assert_se(pa_dbus_protocol_add_interface(u->dbus_protocol, OBJECT_PATH, &stream_restore_interface_info, u) >= 0);
     pa_assert_se(pa_dbus_protocol_register_extension(u->dbus_protocol, INTERFACE_STREAM_RESTORE) >= 0);
@@ -2507,7 +2507,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, (pa_free_cb_t) dbus_entry_free);
+        pa_hashmap_free(u->dbus_entries);
 
         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 6d49acb..678b4b7 100644
--- a/src/modules/module-suspend-on-idle.c
+++ b/src/modules/module-suspend-on-idle.c
@@ -435,7 +435,7 @@ int pa__init(pa_module*m) {
     m->userdata = u = pa_xnew(struct userdata, 1);
     u->core = m->core;
     u->timeout = timeout;
-    u->device_infos = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+    u->device_infos = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL, (pa_free_cb_t) device_info_free);
 
     PA_IDXSET_FOREACH(sink, m->core->sinks, idx)
         device_new_hook_cb(m->core, PA_OBJECT(sink), u);
@@ -518,7 +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);
 
-    pa_hashmap_free(u->device_infos, (pa_free_cb_t) device_info_free);
+    pa_hashmap_free(u->device_infos);
 
     pa_xfree(u);
 }
diff --git a/src/modules/module-systemd-login.c b/src/modules/module-systemd-login.c
index 18f8cc5..8cd5fb0 100644
--- a/src/modules/module-systemd-login.c
+++ b/src/modules/module-systemd-login.c
@@ -140,7 +140,7 @@ static int get_session_list(struct userdata *u) {
         free(sessions);
     }
 
-    pa_hashmap_remove_all(u->previous_sessions, (pa_free_cb_t) free_session);
+    pa_hashmap_remove_all(u->previous_sessions);
 
     return 0;
 }
@@ -187,8 +187,8 @@ int pa__init(pa_module *m) {
     m->userdata = u = pa_xnew0(struct userdata, 1);
     u->core = m->core;
     u->module = m;
-    u->sessions = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    u->previous_sessions = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    u->sessions = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) free_session);
+    u->previous_sessions = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) free_session);
     u->monitor = monitor;
 
     u->io = u->core->mainloop->io_new(u->core->mainloop, sd_login_monitor_get_fd(monitor), PA_IO_EVENT_INPUT, monitor_cb, u);
@@ -219,8 +219,8 @@ void pa__done(pa_module *m) {
         return;
 
     if (u->sessions) {
-        pa_hashmap_free(u->sessions, (pa_free_cb_t) free_session);
-        pa_hashmap_free(u->previous_sessions, (pa_free_cb_t) free_session);
+        pa_hashmap_free(u->sessions);
+        pa_hashmap_free(u->previous_sessions);
     }
 
     if (u->io)
diff --git a/src/modules/module-udev-detect.c b/src/modules/module-udev-detect.c
index fcedfcd..c28c867 100644
--- a/src/modules/module-udev-detect.c
+++ b/src/modules/module-udev-detect.c
@@ -700,7 +700,7 @@ int pa__init(pa_module *m) {
 
     m->userdata = u = pa_xnew0(struct userdata, 1);
     u->core = m->core;
-    u->devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    u->devices = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) device_free);
     u->inotify_fd = -1;
 
     if (pa_modargs_get_value_boolean(ma, "tsched", &use_tsched) < 0) {
@@ -841,7 +841,7 @@ void pa__done(pa_module *m) {
         pa_close(u->inotify_fd);
 
     if (u->devices)
-        pa_hashmap_free(u->devices, (pa_free_cb_t) device_free);
+        pa_hashmap_free(u->devices);
 
     pa_xfree(u);
 }
diff --git a/src/modules/module-zeroconf-discover.c b/src/modules/module-zeroconf-discover.c
index 4ec3747..77782ad 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);
+        pa_hashmap_free(u->tunnels);
     }
 
     pa_xfree(u);
diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c
index 3350008..0110e1d 100644
--- a/src/modules/module-zeroconf-publish.c
+++ b/src/modules/module-zeroconf-publish.c
@@ -745,7 +745,7 @@ int pa__init(pa_module*m) {
 
     u->avahi_poll = pa_avahi_poll_new(u->api);
 
-    u->services = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+    u->services = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL, (pa_free_cb_t) service_free);
 
     u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u);
     u->sink_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u);
@@ -786,7 +786,7 @@ fail:
 static void client_free(pa_mainloop_api *api PA_GCC_UNUSED, void *userdata) {
     struct userdata *u = (struct userdata *) userdata;
 
-    pa_hashmap_free(u->services, (pa_free_cb_t) service_free);
+    pa_hashmap_free(u->services);
 
     if (u->main_entry_group)
         avahi_entry_group_free(u->main_entry_group);
diff --git a/src/modules/raop/module-raop-discover.c b/src/modules/raop/module-raop-discover.c
index c7efe9a..fda5e29 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);
+        pa_hashmap_free(u->tunnels);
     }
 
     pa_xfree(u);
diff --git a/src/modules/rtp/headerlist.c b/src/modules/rtp/headerlist.c
index 9e95e3c..11e076e 100644
--- a/src/modules/rtp/headerlist.c
+++ b/src/modules/rtp/headerlist.c
@@ -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) {
diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c
index 7ff2c75..a4f7733 100644
--- a/src/modules/rtp/module-rtp-recv.c
+++ b/src/modules/rtp/module-rtp-recv.c
@@ -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);
diff --git a/src/pulse/context.c b/src/pulse/context.c
index 3cb9d02..b78df27 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);
+        pa_hashmap_free(c->record_streams);
     if (c->playback_streams)
-        pa_hashmap_free(c->playback_streams, NULL);
+        pa_hashmap_free(c->playback_streams);
 
     if (c->mempool)
         pa_mempool_free(c->mempool);
diff --git a/src/pulse/proplist.c b/src/pulse/proplist.c
index 6e91103..0c2bd60 100644
--- a/src/pulse/proplist.c
+++ b/src/pulse/proplist.c
@@ -64,13 +64,13 @@ static void property_free(struct property *prop) {
 }
 
 pa_proplist* pa_proplist_new(void) {
-    return MAKE_PROPLIST(pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func));
+    return MAKE_PROPLIST(pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) property_free));
 }
 
 void pa_proplist_free(pa_proplist* p) {
     pa_assert(p);
 
-    pa_hashmap_free(MAKE_HASHMAP(p), (pa_free_cb_t) property_free);
+    pa_hashmap_free(MAKE_HASHMAP(p));
 }
 
 /** Will accept only valid UTF-8 */
@@ -654,7 +654,7 @@ int pa_proplist_contains(pa_proplist *p, const char *key) {
 void pa_proplist_clear(pa_proplist *p) {
     pa_assert(p);
 
-    pa_hashmap_remove_all(MAKE_HASHMAP(p), (pa_free_cb_t) property_free);
+    pa_hashmap_remove_all(MAKE_HASHMAP(p));
 }
 
 pa_proplist* pa_proplist_copy(const pa_proplist *p) {
diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
index c771cac..e6e0836 100644
--- a/src/pulsecore/card.c
+++ b/src/pulsecore/card.c
@@ -89,8 +89,8 @@ pa_card_new_data* pa_card_new_data_init(pa_card_new_data *data) {
 
     memset(data, 0, sizeof(*data));
     data->proplist = pa_proplist_new();
-    data->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    data->profiles = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_card_profile_free);
+    data->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_device_port_unref);
     return data;
 }
 
@@ -128,10 +128,10 @@ void pa_card_new_data_done(pa_card_new_data *data) {
     pa_proplist_free(data->proplist);
 
     if (data->profiles)
-        pa_hashmap_free(data->profiles, (pa_free_cb_t) pa_card_profile_free);
+        pa_hashmap_free(data->profiles);
 
     if (data->ports)
-        pa_hashmap_free(data->ports, (pa_free_cb_t) pa_device_port_unref);
+        pa_hashmap_free(data->ports);
 
     pa_xfree(data->name);
     pa_xfree(data->active_profile);
@@ -239,10 +239,10 @@ void pa_card_free(pa_card *c) {
     pa_assert(pa_idxset_isempty(c->sources));
     pa_idxset_free(c->sources, NULL);
 
-    pa_hashmap_free(c->ports, (pa_free_cb_t) pa_device_port_unref);
+    pa_hashmap_free(c->ports);
 
     if (c->profiles)
-        pa_hashmap_free(c->profiles, (pa_free_cb_t) pa_card_profile_free);
+        pa_hashmap_free(c->profiles);
 
     pa_proplist_free(c->proplist);
     pa_xfree(c->driver);
diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c
index b198822..e6f2dfc 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);
 
     pa_assert(pa_hashmap_isempty(c->namereg));
-    pa_hashmap_free(c->namereg, NULL);
+    pa_hashmap_free(c->namereg);
 
     pa_assert(pa_hashmap_isempty(c->shared));
-    pa_hashmap_free(c->shared, NULL);
+    pa_hashmap_free(c->shared);
 
     pa_subscription_free_all(c);
 
diff --git a/src/pulsecore/database-simple.c b/src/pulsecore/database-simple.c
index 0d22e5b..562c9ab 100644
--- a/src/pulsecore/database-simple.c
+++ b/src/pulsecore/database-simple.c
@@ -238,7 +238,7 @@ pa_database* pa_database_open(const char *fn, bool for_write) {
 
     if (f || errno == ENOENT) { /* file not found is ok */
         db = pa_xnew0(simple_data, 1);
-        db->map = pa_hashmap_new(hash_func, compare_func);
+        db->map = pa_hashmap_new_full(hash_func, compare_func, NULL, (pa_free_cb_t) free_entry);
         db->filename = pa_xstrdup(path);
         db->tmp_filename = pa_sprintf_malloc(".%s.tmp", db->filename);
         db->read_only = !for_write;
@@ -265,7 +265,7 @@ void pa_database_close(pa_database *database) {
     pa_database_sync(database);
     pa_xfree(db->filename);
     pa_xfree(db->tmp_filename);
-    pa_hashmap_free(db->map, (pa_free_cb_t) free_entry);
+    pa_hashmap_free(db->map);
     pa_xfree(db);
 }
 
@@ -341,7 +341,7 @@ int pa_database_clear(pa_database *database) {
 
     pa_assert(db);
 
-    pa_hashmap_remove_all(db->map, (pa_free_cb_t) free_entry);
+    pa_hashmap_remove_all(db->map);
 
     return 0;
 }
diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 8bff5b6..0b65d5c 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -98,7 +98,7 @@ static void device_port_free(pa_object *o) {
         pa_proplist_free(p->proplist);
 
     if (p->profiles)
-        pa_hashmap_free(p->profiles, NULL);
+        pa_hashmap_free(p->profiles);
 
     pa_xfree(p->name);
     pa_xfree(p->description);
diff --git a/src/pulsecore/hashmap.c b/src/pulsecore/hashmap.c
index 0629164..acac1e0 100644
--- a/src/pulsecore/hashmap.c
+++ b/src/pulsecore/hashmap.c
@@ -35,7 +35,7 @@
 #define NBUCKETS 127
 
 struct hashmap_entry {
-    const void *key;
+    void *key;
     void *value;
 
     struct hashmap_entry *bucket_next, *bucket_previous;
@@ -46,6 +46,9 @@ struct pa_hashmap {
     pa_hash_func_t hash_func;
     pa_compare_func_t compare_func;
 
+    pa_free_cb_t key_free_func;
+    pa_free_cb_t value_free_func;
+
     struct hashmap_entry *iterate_list_head, *iterate_list_tail;
     unsigned n_entries;
 };
@@ -54,7 +57,7 @@ struct pa_hashmap {
 
 PA_STATIC_FLIST_DECLARE(entries, 0, pa_xfree);
 
-pa_hashmap *pa_hashmap_new(pa_hash_func_t hash_func, pa_compare_func_t compare_func) {
+pa_hashmap *pa_hashmap_new_full(pa_hash_func_t hash_func, pa_compare_func_t compare_func, pa_free_cb_t key_free_func, pa_free_cb_t value_free_func) {
     pa_hashmap *h;
 
     h = pa_xmalloc0(PA_ALIGN(sizeof(pa_hashmap)) + NBUCKETS*sizeof(struct hashmap_entry*));
@@ -62,12 +65,19 @@ pa_hashmap *pa_hashmap_new(pa_hash_func_t hash_func, pa_compare_func_t compare_f
     h->hash_func = hash_func ? hash_func : pa_idxset_trivial_hash_func;
     h->compare_func = compare_func ? compare_func : pa_idxset_trivial_compare_func;
 
+    h->key_free_func = key_free_func;
+    h->value_free_func = value_free_func;
+
     h->n_entries = 0;
     h->iterate_list_head = h->iterate_list_tail = NULL;
 
     return h;
 }
 
+pa_hashmap *pa_hashmap_new(pa_hash_func_t hash_func, pa_compare_func_t compare_func) {
+    return pa_hashmap_new_full(hash_func, compare_func, NULL, NULL);
+}
+
 static void remove_entry(pa_hashmap *h, struct hashmap_entry *e) {
     pa_assert(h);
     pa_assert(e);
@@ -94,6 +104,9 @@ static void remove_entry(pa_hashmap *h, struct hashmap_entry *e) {
         BY_HASH(h)[hash] = e->bucket_next;
     }
 
+    if (h->key_free_func)
+        h->key_free_func(e->key);
+
     if (pa_flist_push(PA_STATIC_FLIST_GET(entries), e) < 0)
         pa_xfree(e);
 
@@ -101,10 +114,10 @@ static void remove_entry(pa_hashmap *h, struct hashmap_entry *e) {
     h->n_entries--;
 }
 
-void pa_hashmap_free(pa_hashmap *h, pa_free_cb_t free_cb) {
+void pa_hashmap_free(pa_hashmap *h) {
     pa_assert(h);
 
-    pa_hashmap_remove_all(h, free_cb);
+    pa_hashmap_remove_all(h);
     pa_xfree(h);
 }
 
@@ -120,7 +133,7 @@ static struct hashmap_entry *hash_scan(pa_hashmap *h, unsigned hash, const void
     return NULL;
 }
 
-int pa_hashmap_put(pa_hashmap *h, const void *key, void *value) {
+int pa_hashmap_put(pa_hashmap *h, void *key, void *value) {
     struct hashmap_entry *e;
     unsigned hash;
 
@@ -194,7 +207,7 @@ void* pa_hashmap_remove(pa_hashmap *h, const void *key) {
     return data;
 }
 
-void pa_hashmap_remove_all(pa_hashmap *h, pa_free_cb_t free_cb) {
+void pa_hashmap_remove_all(pa_hashmap *h) {
     pa_assert(h);
 
     while (h->iterate_list_head) {
@@ -202,8 +215,8 @@ void pa_hashmap_remove_all(pa_hashmap *h, pa_free_cb_t free_cb) {
         data = h->iterate_list_head->value;
         remove_entry(h, h->iterate_list_head);
 
-        if (free_cb)
-            free_cb(data);
+        if (h->value_free_func)
+            h->value_free_func(data);
     }
 }
 
diff --git a/src/pulsecore/hashmap.h b/src/pulsecore/hashmap.h
index a57fab3..ae030ed 100644
--- a/src/pulsecore/hashmap.h
+++ b/src/pulsecore/hashmap.h
@@ -36,11 +36,15 @@ typedef struct pa_hashmap pa_hashmap;
 /* Create a new hashmap. Use the specified functions for hashing and comparing objects in the map */
 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_free_cb_t free_cb);
+/* Create a new hashmap. Use the specified functions for hashing and comparing objects in the map, and functions to free the key
+ * and value (either or both can be NULL). */
+pa_hashmap *pa_hashmap_new_full(pa_hash_func_t hash_func, pa_compare_func_t compare_func, pa_free_cb_t key_free_func, pa_free_cb_t value_free_func);
+
+/* Free the hash table. */
+void pa_hashmap_free(pa_hashmap*);
 
 /* 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, void *key, void *value);
 
 /* Return an entry from the hashmap */
 void* pa_hashmap_get(pa_hashmap *h, const void *key);
@@ -48,8 +52,8 @@ void* pa_hashmap_get(pa_hashmap *h, const void *key);
 /* Returns the data of the entry while removing */
 void* pa_hashmap_remove(pa_hashmap *h, const void *key);
 
-/* If free_cb is not NULL, it's called for each entry. */
-void pa_hashmap_remove_all(pa_hashmap *h, pa_free_cb_t free_cb);
+/* Remove all entries but don't free the hashmap */
+void pa_hashmap_remove_all(pa_hashmap *h);
 
 /* Return the current number of entries of the hashmap */
 unsigned pa_hashmap_size(pa_hashmap *h);
diff --git a/src/pulsecore/memblock.c b/src/pulsecore/memblock.c
index 2d83b72..acfb481 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);
-    pa_hashmap_free(i->segments, NULL);
+    pa_hashmap_free(i->blocks);
+    pa_hashmap_free(i->segments);
 
     pa_mutex_free(i->mutex);
 
diff --git a/src/pulsecore/modargs.c b/src/pulsecore/modargs.c
index 09ca9fc..7665b91 100644
--- a/src/pulsecore/modargs.c
+++ b/src/pulsecore/modargs.c
@@ -93,6 +93,15 @@ static int add_key_value(pa_modargs *ma, char *key, char *value, const char* con
     return 0;
 }
 
+static void free_func(void *p) {
+    struct entry *e = p;
+    pa_assert(e);
+
+    pa_xfree(e->key);
+    pa_xfree(e->value);
+    pa_xfree(e);
+}
+
 pa_modargs *pa_modargs_new(const char *args, const char* const* valid_keys) {
     enum {
         WHITESPACE,
@@ -110,8 +119,8 @@ pa_modargs *pa_modargs_new(const char *args, const char* const* valid_keys) {
     size_t key_len = 0, value_len = 0;
     pa_modargs *ma = pa_xnew(pa_modargs, 1);
 
-    ma->raw = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    ma->unescaped = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    ma->raw = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, free_func);
+    ma->unescaped = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, free_func);
 
     if (!args)
         return ma;
@@ -247,20 +256,11 @@ fail:
     return NULL;
 }
 
-static void free_func(void *p) {
-    struct entry *e = p;
-    pa_assert(e);
-
-    pa_xfree(e->key);
-    pa_xfree(e->value);
-    pa_xfree(e);
-}
-
 void pa_modargs_free(pa_modargs*ma) {
     pa_assert(ma);
 
-    pa_hashmap_free(ma->raw, free_func);
-    pa_hashmap_free(ma->unescaped, free_func);
+    pa_hashmap_free(ma->raw);
+    pa_hashmap_free(ma->unescaped);
     pa_xfree(ma);
 }
 
diff --git a/src/pulsecore/mutex-win32.c b/src/pulsecore/mutex-win32.c
index 01e8b4a..46935a7 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);
+    pa_hashmap_free(c->wait_events);
     pa_xfree(c);
 }
 
diff --git a/src/pulsecore/protocol-dbus.c b/src/pulsecore/protocol-dbus.c
index 0ff4d83..c0d1ec4 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);
-    pa_hashmap_free(p->connections, NULL);
+    pa_hashmap_free(p->objects);
+    pa_hashmap_free(p->connections);
     pa_idxset_free(p->extensions, NULL);
 
     for (i = 0; i < PA_DBUS_PROTOCOL_HOOK_MAX; ++i)
@@ -633,6 +633,23 @@ static pa_dbus_arg_info *copy_args(const pa_dbus_arg_info *src, unsigned n) {
     return dst;
 }
 
+static void method_handler_free(pa_dbus_method_handler *h) {
+    unsigned i;
+
+    pa_assert(h);
+
+    pa_xfree((char *) h->method_name);
+
+    for (i = 0; i < h->n_arguments; ++i) {
+        pa_xfree((char *) h->arguments[i].name);
+        pa_xfree((char *) h->arguments[i].type);
+        pa_xfree((char *) h->arguments[i].direction);
+    }
+
+    pa_xfree((pa_dbus_arg_info *) h->arguments);
+    pa_xfree(h);
+}
+
 static pa_hashmap *create_method_handlers(const pa_dbus_interface_info *info) {
     pa_hashmap *handlers;
     unsigned i;
@@ -640,7 +657,7 @@ static pa_hashmap *create_method_handlers(const pa_dbus_interface_info *info) {
     pa_assert(info);
     pa_assert(info->method_handlers || info->n_method_handlers == 0);
 
-    handlers = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    handlers = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) method_handler_free);
 
     for (i = 0; i < info->n_method_handlers; ++i) {
         pa_dbus_method_handler *h = pa_xnew(pa_dbus_method_handler, 1);
@@ -649,7 +666,7 @@ static pa_hashmap *create_method_handlers(const pa_dbus_interface_info *info) {
         h->n_arguments = info->method_handlers[i].n_arguments;
         h->receive_cb = info->method_handlers[i].receive_cb;
 
-        pa_hashmap_put(handlers, h->method_name, h);
+        pa_hashmap_put(handlers, (char *) h->method_name, h);
     }
 
     return handlers;
@@ -664,7 +681,7 @@ static pa_hashmap *extract_method_signatures(pa_hashmap *method_handlers) {
 
     pa_assert(method_handlers);
 
-    signatures = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    signatures = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, pa_xfree);
 
     PA_HASHMAP_FOREACH(handler, method_handlers, state) {
         sig_buf = pa_strbuf_new();
@@ -674,12 +691,21 @@ static pa_hashmap *extract_method_signatures(pa_hashmap *method_handlers) {
                 pa_strbuf_puts(sig_buf, handler->arguments[i].type);
         }
 
-        pa_hashmap_put(signatures, handler->method_name, pa_strbuf_tostring_free(sig_buf));
+        pa_hashmap_put(signatures, (char *) handler->method_name, pa_strbuf_tostring_free(sig_buf));
     }
 
     return signatures;
 }
 
+static void property_handler_free(pa_dbus_property_handler *h) {
+    pa_assert(h);
+
+    pa_xfree((char *) h->property_name);
+    pa_xfree((char *) h->type);
+
+    pa_xfree(h);
+}
+
 static pa_hashmap *create_property_handlers(const pa_dbus_interface_info *info) {
     pa_hashmap *handlers;
     unsigned i = 0;
@@ -687,7 +713,7 @@ static pa_hashmap *create_property_handlers(const pa_dbus_interface_info *info)
     pa_assert(info);
     pa_assert(info->property_handlers || info->n_property_handlers == 0);
 
-    handlers = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    handlers = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) property_handler_free);
 
     for (i = 0; i < info->n_property_handlers; ++i) {
         pa_dbus_property_handler *h = pa_xnew(pa_dbus_property_handler, 1);
@@ -696,7 +722,7 @@ static pa_hashmap *create_property_handlers(const pa_dbus_interface_info *info)
         h->get_cb = info->property_handlers[i].get_cb;
         h->set_cb = info->property_handlers[i].set_cb;
 
-        pa_hashmap_put(handlers, h->property_name, h);
+        pa_hashmap_put(handlers, (char *) h->property_name, h);
     }
 
     return handlers;
@@ -789,32 +815,6 @@ 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(pa_dbus_method_handler *h) {
-    unsigned i;
-
-    pa_assert(h);
-
-    pa_xfree((char *) h->method_name);
-
-    for (i = 0; i < h->n_arguments; ++i) {
-        pa_xfree((char *) h->arguments[i].name);
-        pa_xfree((char *) h->arguments[i].type);
-        pa_xfree((char *) h->arguments[i].direction);
-    }
-
-    pa_xfree((pa_dbus_arg_info *) h->arguments);
-    pa_xfree(h);
-}
-
-static void property_handler_free(pa_dbus_property_handler *h) {
-    pa_assert(h);
-
-    pa_xfree((char *) h->property_name);
-    pa_xfree((char *) h->type);
-
-    pa_xfree(h);
-}
-
 int pa_dbus_protocol_remove_interface(pa_dbus_protocol *p, const char* path, const char* interface) {
     struct object_entry *obj_entry;
     struct interface_entry *iface_entry;
@@ -835,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, 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);
+    pa_hashmap_free(iface_entry->method_signatures);
+    pa_hashmap_free(iface_entry->method_handlers);
+    pa_hashmap_free(iface_entry->property_handlers);
 
     for (i = 0; i < iface_entry->n_signals; ++i) {
         unsigned j;
@@ -861,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);
+        pa_hashmap_free(obj_entry->interfaces);
         pa_xfree(obj_entry->introspection);
         pa_xfree(obj_entry);
     }
@@ -880,6 +880,14 @@ static void register_all_objects(pa_dbus_protocol *p, DBusConnection *conn) {
         pa_assert_se(dbus_connection_register_object_path(conn, obj_entry->path, &vtable, p));
 }
 
+static void signal_paths_entry_free(struct signal_paths_entry *e) {
+    pa_assert(e);
+
+    pa_xfree(e->signal);
+    pa_idxset_free(e->paths, pa_xfree);
+    pa_xfree(e);
+}
+
 int pa_dbus_protocol_register_connection(pa_dbus_protocol *p, DBusConnection *conn, pa_client *client) {
     struct connection_entry *conn_entry;
 
@@ -897,7 +905,8 @@ int pa_dbus_protocol_register_connection(pa_dbus_protocol *p, DBusConnection *co
     conn_entry->client = client;
     conn_entry->listening_for_all_signals = false;
     conn_entry->all_signals_objects = pa_idxset_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    conn_entry->listening_signals = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    conn_entry->listening_signals = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL,
+                                                        (pa_free_cb_t) signal_paths_entry_free);
 
     pa_hashmap_put(p->connections, conn, conn_entry);
 
@@ -927,14 +936,6 @@ static struct signal_paths_entry *signal_paths_entry_new(const char *signal_name
     return e;
 }
 
-static void signal_paths_entry_free(struct signal_paths_entry *e) {
-    pa_assert(e);
-
-    pa_xfree(e->signal);
-    pa_idxset_free(e->paths, pa_xfree);
-    pa_xfree(e);
-}
-
 int pa_dbus_protocol_unregister_connection(pa_dbus_protocol *p, DBusConnection *conn) {
     struct connection_entry *conn_entry = NULL;
 
@@ -948,7 +949,7 @@ int pa_dbus_protocol_unregister_connection(pa_dbus_protocol *p, DBusConnection *
 
     dbus_connection_unref(conn_entry->connection);
     pa_idxset_free(conn_entry->all_signals_objects, pa_xfree);
-    pa_hashmap_free(conn_entry->listening_signals, (pa_free_cb_t) signal_paths_entry_free);
+    pa_hashmap_free(conn_entry->listening_signals);
     pa_xfree(conn_entry);
 
     return 0;
@@ -1006,7 +1007,7 @@ void pa_dbus_protocol_add_signal_listener(
 
         /* We're not interested in individual signals anymore, so let's empty
          * listening_signals. */
-        pa_hashmap_remove_all(conn_entry->listening_signals, (pa_free_cb_t) signal_paths_entry_free);
+        pa_hashmap_remove_all(conn_entry->listening_signals);
 
         for (i = 0; i < n_objects; ++i)
             pa_idxset_put(conn_entry->all_signals_objects, pa_xstrdup(objects[i]), NULL);
@@ -1029,7 +1030,7 @@ void pa_dbus_protocol_remove_signal_listener(pa_dbus_protocol *p, DBusConnection
     } else {
         conn_entry->listening_for_all_signals = false;
         pa_idxset_remove_all(conn_entry->all_signals_objects, pa_xfree);
-        pa_hashmap_remove_all(conn_entry->listening_signals, (pa_free_cb_t) signal_paths_entry_free);
+        pa_hashmap_remove_all(conn_entry->listening_signals);
     }
 }
 
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index 9342c1a..a5a0d4e 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -5139,7 +5139,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);
+    pa_hashmap_free(p->extensions);
 
     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 b5e8a0b..5164d27 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -109,8 +109,10 @@ pa_sink_input_new_data* pa_sink_input_new_data_init(pa_sink_input_new_data *data
     data->proplist = pa_proplist_new();
     data->volume_writable = true;
 
-    data->volume_factor_items = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-    data->volume_factor_sink_items = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    data->volume_factor_items = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL,
+                                                    (pa_free_cb_t) volume_factor_entry_free);
+    data->volume_factor_sink_items = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL,
+                                                         (pa_free_cb_t) volume_factor_entry_free);
 
     return data;
 }
@@ -241,10 +243,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_free_cb_t) volume_factor_entry_free);
+        pa_hashmap_free(data->volume_factor_items);
 
     if (data->volume_factor_sink_items)
-        pa_hashmap_free(data->volume_factor_sink_items, (pa_free_cb_t) volume_factor_entry_free);
+        pa_hashmap_free(data->volume_factor_sink_items);
 
     pa_proplist_free(data->proplist);
 }
@@ -766,13 +768,13 @@ static void sink_input_free(pa_object *o) {
         pa_idxset_free(i->direct_outputs, NULL);
 
     if (i->thread_info.direct_outputs)
-        pa_hashmap_free(i->thread_info.direct_outputs, NULL);
+        pa_hashmap_free(i->thread_info.direct_outputs);
 
     if (i->volume_factor_items)
-        pa_hashmap_free(i->volume_factor_items, (pa_free_cb_t) volume_factor_entry_free);
+        pa_hashmap_free(i->volume_factor_items);
 
     if (i->volume_factor_sink_items)
-        pa_hashmap_free(i->volume_factor_sink_items, (pa_free_cb_t) volume_factor_entry_free);
+        pa_hashmap_free(i->volume_factor_sink_items);
 
     pa_xfree(i->driver);
     pa_xfree(i);
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index de8c82e..81fefbc 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -82,7 +82,7 @@ pa_sink_new_data* pa_sink_new_data_init(pa_sink_new_data *data) {
 
     pa_zero(*data);
     data->proplist = pa_proplist_new();
-    data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    data->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_device_port_unref);
 
     return data;
 }
@@ -142,7 +142,7 @@ void pa_sink_new_data_done(pa_sink_new_data *data) {
     pa_proplist_free(data->proplist);
 
     if (data->ports)
-        pa_hashmap_free(data->ports, (pa_free_cb_t) pa_device_port_unref);
+        pa_hashmap_free(data->ports);
 
     pa_xfree(data->name);
     pa_xfree(data->active_port);
@@ -325,7 +325,8 @@ pa_sink* pa_sink_new(
             0);
 
     s->thread_info.rtpoll = NULL;
-    s->thread_info.inputs = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+    s->thread_info.inputs = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL,
+                                                (pa_free_cb_t) pa_sink_input_unref);
     s->thread_info.soft_volume =  s->soft_volume;
     s->thread_info.soft_muted = s->muted;
     s->thread_info.state = s->state;
@@ -730,7 +731,7 @@ static void sink_free(pa_object *o) {
     }
 
     pa_idxset_free(s->inputs, NULL);
-    pa_hashmap_free(s->thread_info.inputs, (pa_free_cb_t) pa_sink_input_unref);
+    pa_hashmap_free(s->thread_info.inputs);
 
     if (s->silence.memblock)
         pa_memblock_unref(s->silence.memblock);
@@ -742,7 +743,7 @@ static void sink_free(pa_object *o) {
         pa_proplist_free(s->proplist);
 
     if (s->ports)
-        pa_hashmap_free(s->ports, (pa_free_cb_t) pa_device_port_unref);
+        pa_hashmap_free(s->ports);
 
     pa_xfree(s);
 }
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index f695655..92411de 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -73,7 +73,7 @@ pa_source_new_data* pa_source_new_data_init(pa_source_new_data *data) {
 
     pa_zero(*data);
     data->proplist = pa_proplist_new();
-    data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
+    data->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_device_port_unref);
 
     return data;
 }
@@ -133,7 +133,7 @@ void pa_source_new_data_done(pa_source_new_data *data) {
     pa_proplist_free(data->proplist);
 
     if (data->ports)
-        pa_hashmap_free(data->ports, (pa_free_cb_t) pa_device_port_unref);
+        pa_hashmap_free(data->ports);
 
     pa_xfree(data->name);
     pa_xfree(data->active_port);
@@ -313,7 +313,8 @@ pa_source* pa_source_new(
             0);
 
     s->thread_info.rtpoll = NULL;
-    s->thread_info.outputs = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+    s->thread_info.outputs = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL,
+                                                 (pa_free_cb_t) pa_source_output_unref);
     s->thread_info.soft_volume = s->soft_volume;
     s->thread_info.soft_muted = s->muted;
     s->thread_info.state = s->state;
@@ -660,7 +661,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);
-    pa_hashmap_free(s->thread_info.outputs, (pa_free_cb_t) pa_source_output_unref);
+    pa_hashmap_free(s->thread_info.outputs);
 
     if (s->silence.memblock)
         pa_memblock_unref(s->silence.memblock);
@@ -672,7 +673,7 @@ static void source_free(pa_object *o) {
         pa_proplist_free(s->proplist);
 
     if (s->ports)
-        pa_hashmap_free(s->ports, (pa_free_cb_t) pa_device_port_unref);
+        pa_hashmap_free(s->ports);
 
     pa_xfree(s);
 }
-- 
1.8.3.1



More information about the pulseaudio-discuss mailing list