render/allocator/drm_dumb: fix error handling

In the CREATE_DUMB error code-path, we'd only free() the buffer,
however it's already inserted in the alloc->buffers list at this
point.

Instead, make sure finish_buffer() is safe to call (by populating
drm_fd) and call that function.
This commit is contained in:
Simon Ser 2022-10-01 17:52:34 +02:00 committed by Alexander Orzechowski
parent 3e7ea8715b
commit c659792d7b

View file

@ -70,6 +70,8 @@ static struct wlr_drm_dumb_buffer *create_buffer(
wlr_buffer_init(&buffer->base, &buffer_impl, width, height); wlr_buffer_init(&buffer->base, &buffer_impl, width, height);
wl_list_insert(&alloc->buffers, &buffer->link); wl_list_insert(&alloc->buffers, &buffer->link);
buffer->drm_fd = alloc->drm_fd;
struct drm_mode_create_dumb create = {0}; struct drm_mode_create_dumb create = {0};
create.width = (uint32_t)width; create.width = (uint32_t)width;
create.height = (uint32_t)height; create.height = (uint32_t)height;
@ -77,7 +79,7 @@ static struct wlr_drm_dumb_buffer *create_buffer(
if (drmIoctl(alloc->drm_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create) != 0) { if (drmIoctl(alloc->drm_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create) != 0) {
wlr_log_errno(WLR_ERROR, "Failed to create DRM dumb buffer"); wlr_log_errno(WLR_ERROR, "Failed to create DRM dumb buffer");
goto create_err; goto create_destroy;
} }
buffer->width = create.width; buffer->width = create.width;
@ -87,8 +89,6 @@ static struct wlr_drm_dumb_buffer *create_buffer(
buffer->handle = create.handle; buffer->handle = create.handle;
buffer->format = format->format; buffer->format = format->format;
buffer->drm_fd = alloc->drm_fd;
struct drm_mode_map_dumb map = {0}; struct drm_mode_map_dumb map = {0};
map.handle = buffer->handle; map.handle = buffer->handle;
@ -133,7 +133,6 @@ static struct wlr_drm_dumb_buffer *create_buffer(
create_destroy: create_destroy:
finish_buffer(buffer); finish_buffer(buffer);
create_err:
free(buffer); free(buffer);
return NULL; return NULL;
} }