backend/headless: create renderer after wlr_backend_init

We were calling wlr_renderer_autocreate before wlr_backend_init,
which caused a NULL dereference on wlr_backend.impl.
This commit is contained in:
Simon Ser 2021-01-17 01:08:40 +01:00
parent 9e98f497af
commit c6c7fccd96
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
1 changed files with 9 additions and 9 deletions

View File

@ -120,6 +120,14 @@ static bool backend_init(struct wlr_headless_backend *backend,
wl_list_init(&backend->input_devices); wl_list_init(&backend->input_devices);
backend->allocator = allocator; backend->allocator = allocator;
if (renderer == NULL) {
renderer = wlr_renderer_autocreate(&backend->backend);
if (!renderer) {
wlr_log(WLR_ERROR, "Failed to create renderer");
return false;
}
}
backend->renderer = renderer; backend->renderer = renderer;
const struct wlr_drm_format_set *formats = const struct wlr_drm_format_set *formats =
@ -219,21 +227,13 @@ struct wlr_backend *wlr_headless_backend_create(struct wl_display *display) {
goto error_dup; goto error_dup;
} }
struct wlr_renderer *renderer = wlr_renderer_autocreate(&backend->backend); if (!backend_init(backend, display, &gbm_alloc->base, NULL)) {
if (!renderer) {
wlr_log(WLR_ERROR, "Failed to create renderer");
goto error_renderer;
}
if (!backend_init(backend, display, &gbm_alloc->base, renderer)) {
goto error_init; goto error_init;
} }
return &backend->backend; return &backend->backend;
error_init: error_init:
wlr_renderer_destroy(renderer);
error_renderer:
wlr_allocator_destroy(&gbm_alloc->base); wlr_allocator_destroy(&gbm_alloc->base);
error_dup: error_dup:
close(backend->drm_fd); close(backend->drm_fd);