static void test_hashmap_remove_value(void) { _cleanup_hashmap_free_ Hashmap *m = NULL; char *r; r = hashmap_remove_value(NULL, "key 1", (void*) "val 1"); assert_se(r == NULL); m = hashmap_new(&string_hash_ops); assert_se(m); r = hashmap_remove_value(m, "key 1", (void*) "val 1"); assert_se(r == NULL); hashmap_put(m, "key 1", (void*) "val 1"); hashmap_put(m, "key 2", (void*) "val 2"); r = hashmap_remove_value(m, "key 1", (void*) "val 1"); assert_se(streq(r, "val 1")); r = hashmap_get(m, "key 2"); assert_se(streq(r, "val 2")); assert_se(!hashmap_get(m, "key 1")); r = hashmap_remove_value(m, "key 2", (void*) "val 1"); assert_se(r == NULL); r = hashmap_get(m, "key 2"); assert_se(streq(r, "val 2")); assert_se(!hashmap_get(m, "key 1")); }
static void test_hashmap_remove_value(void) { _cleanup_hashmap_free_ Hashmap *m = NULL; char *r; char val1[] = "val 1"; char val2[] = "val 2"; log_info("%s", __func__); r = hashmap_remove_value(NULL, "key 1", val1); assert_se(r == NULL); m = hashmap_new(&string_hash_ops); assert_se(m); r = hashmap_remove_value(m, "key 1", val1); assert_se(r == NULL); hashmap_put(m, "key 1", val1); hashmap_put(m, "key 2", val2); r = hashmap_remove_value(m, "key 1", val1); assert_se(streq(r, "val 1")); r = hashmap_get(m, "key 2"); assert_se(streq(r, "val 2")); assert_se(!hashmap_get(m, "key 1")); r = hashmap_remove_value(m, "key 2", val1); assert_se(r == NULL); r = hashmap_get(m, "key 2"); assert_se(streq(r, "val 2")); assert_se(!hashmap_get(m, "key 1")); }
static kbdctx *kbdctx_unref(kbdctx *kc) { if (!kc) return NULL; assert_return(kc->ref > 0, NULL); if (--kc->ref > 0) return NULL; free(kc->last_x11_options); free(kc->last_x11_variant); free(kc->last_x11_layout); free(kc->last_x11_model); free(kc->locale_x11_options); free(kc->locale_x11_variant); free(kc->locale_x11_layout); free(kc->locale_x11_model); free(kc->locale_lang); kc->slot_locale_get_all = sd_bus_slot_unref(kc->slot_locale_get_all); kc->slot_locale_props_changed = sd_bus_slot_unref(kc->slot_locale_props_changed); kc->kbdtbl = kbdtbl_unref(kc->kbdtbl); kc->kbdmap = kbdmap_unref(kc->kbdmap); xkb_context_unref(kc->xkb_context); hashmap_remove_value(kc->context->data_map, KBDCTX_KEY, kc); free(kc); return NULL; }
sysview_session *sysview_session_free(sysview_session *session) { if (!session) return NULL; assert(!session->public); assert(!session->wants_control); if (session->name) { hashmap_remove_value(session->seat->session_map, session->name, session); hashmap_remove_value(session->seat->context->session_map, session->name, session); } free(session->path); free(session->name); free(session); return NULL; }
void buxton_close(BuxtonClient client) { _BuxtonClient *c; BuxtonKey key = NULL; Iterator i; /* Free all remaining allocated keys */ HASHMAP_FOREACH_KEY(key, key, key_hash, i) { hashmap_remove_value(key_hash, key, key); buxton_key_free(key); }
sysview_device *sysview_device_free(sysview_device *device) { if (!device) return NULL; if (device->name) { hashmap_remove_value(device->seat->device_map, device->name, device); hashmap_remove_value(device->seat->context->device_map, device->name, device); } switch (device->type) { case SYSVIEW_DEVICE_EVDEV: device->evdev.ud = udev_device_unref(device->evdev.ud); break; case SYSVIEW_DEVICE_DRM: device->drm.ud = udev_device_unref(device->drm.ud); break; } free(device->name); free(device); return NULL; }
sysview_seat *sysview_seat_free(sysview_seat *seat) { if (!seat) return NULL; assert(!seat->public); assert(hashmap_size(seat->device_map) == 0); assert(hashmap_size(seat->session_map) == 0); if (seat->name) hashmap_remove_value(seat->context->seat_map, seat->name, seat); hashmap_free(seat->device_map); hashmap_free(seat->session_map); free(seat->name); free(seat); return NULL; }