bar/wayland: wl_* APIs typically don't handle destroy(NULL)

This commit is contained in:
Daniel Eklöf 2019-02-07 11:22:02 +01:00
parent a831490462
commit 0fc5778107

View file

@ -118,7 +118,8 @@ static const struct wl_shm_listener shm_listener = {
static void static void
update_cursor_surface(struct wayland_backend *backend) update_cursor_surface(struct wayland_backend *backend)
{ {
assert(backend->pointer.cursor != NULL); if (backend->pointer.cursor == NULL)
return;
struct wl_cursor_image *image = backend->pointer.cursor->images[0]; struct wl_cursor_image *image = backend->pointer.cursor->images[0];
@ -582,36 +583,55 @@ cleanup(struct bar *_bar)
struct wayland_backend *backend = bar->backend.data; struct wayland_backend *backend = bar->backend.data;
tll_foreach(backend->buffers, it) { tll_foreach(backend->buffers, it) {
if (it->item.wl_buf != NULL)
wl_buffer_destroy(it->item.wl_buf); wl_buffer_destroy(it->item.wl_buf);
if (it->item.cairo != NULL)
cairo_destroy(it->item.cairo); cairo_destroy(it->item.cairo);
if (it->item.cairo_surface != NULL)
cairo_surface_destroy(it->item.cairo_surface); cairo_surface_destroy(it->item.cairo_surface);
munmap(it->item.mmapped, it->item.size);
munmap(it->item.mmapped, it->item.size);
tll_remove(backend->buffers, it); tll_remove(backend->buffers, it);
} }
tll_foreach(backend->monitors, it) { tll_foreach(backend->monitors, it) {
struct monitor *mon = &it->item; struct monitor *mon = &it->item;
free(mon->name); free(mon->name);
if (mon->xdg != NULL)
zxdg_output_v1_destroy(mon->xdg); zxdg_output_v1_destroy(mon->xdg);
if (mon->output != NULL)
wl_output_destroy(mon->output); wl_output_destroy(mon->output);
tll_remove(backend->monitors, it); tll_remove(backend->monitors, it);
} }
if (backend->xdg_output_manager != NULL)
zxdg_output_manager_v1_destroy(backend->xdg_output_manager); zxdg_output_manager_v1_destroy(backend->xdg_output_manager);
/* TODO: move to bar */ /* TODO: move to bar */
free(bar->cursor_name); free(bar->cursor_name);
if (backend->layer_surface != NULL)
zwlr_layer_surface_v1_destroy(backend->layer_surface); zwlr_layer_surface_v1_destroy(backend->layer_surface);
if (backend->layer_shell != NULL)
zwlr_layer_shell_v1_destroy(backend->layer_shell); zwlr_layer_shell_v1_destroy(backend->layer_shell);
if (backend->pointer.theme != NULL)
wl_cursor_theme_destroy(backend->pointer.theme); wl_cursor_theme_destroy(backend->pointer.theme);
if (backend->pointer.pointer != NULL)
wl_pointer_destroy(backend->pointer.pointer); wl_pointer_destroy(backend->pointer.pointer);
if (backend->pointer.surface != NULL)
wl_surface_destroy(backend->pointer.surface); wl_surface_destroy(backend->pointer.surface);
if (backend->surface != NULL)
wl_surface_destroy(backend->surface); wl_surface_destroy(backend->surface);
if (backend->seat != NULL)
wl_seat_destroy(backend->seat); wl_seat_destroy(backend->seat);
if (backend->compositor != NULL)
wl_compositor_destroy(backend->compositor); wl_compositor_destroy(backend->compositor);
if (backend->shm != NULL)
wl_shm_destroy(backend->shm); wl_shm_destroy(backend->shm);
if (backend->registry != NULL)
wl_registry_destroy(backend->registry); wl_registry_destroy(backend->registry);
if (backend->display != NULL)
wl_display_disconnect(backend->display); wl_display_disconnect(backend->display);
/* Destroyed when freeing buffer list */ /* Destroyed when freeing buffer list */