Prevent alloc errors from crashing in list_t

This commit changes the `list_t` api so that alloc errors can be
detected and worked around. Also fixes errors not found in 5cc7342
This commit is contained in:
Calvin Lee 2017-08-16 09:23:21 +02:00
parent 19d6442f52
commit 901c14c409
8 changed files with 103 additions and 25 deletions

View file

@ -236,7 +236,8 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) {
output->egl_surface, output->egl_surface,
output->backend->egl.context)) {
wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error());
return false;
free(output);
return NULL;
}
glViewport(0, 0, wlr_output->width, wlr_output->height);
@ -248,11 +249,16 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) {
if (!eglSwapBuffers(output->backend->egl.display, output->egl_surface)) {
wlr_log(L_ERROR, "eglSwapBuffers failed: %s", egl_error());
return false;
free(output);
return NULL;
}
if (list_add(backend->outputs, wlr_output) == -1) {
wlr_log(L_ERROR, "Allocation failed");
free(output);
return NULL;
}
wlr_output_create_global(wlr_output, backend->local_display);
list_add(backend->outputs, wlr_output);
wl_signal_emit(&backend->backend.events.output_add, wlr_output);
return wlr_output;
}

View file

@ -188,7 +188,7 @@ static struct wlr_input_device *allocate_device(struct wlr_wl_backend *backend,
enum wlr_input_device_type type) {
struct wlr_wl_input_device *wlr_wl_dev;
if (!(wlr_wl_dev = calloc(1, sizeof(struct wlr_wl_input_device)))) {
wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno));
wlr_log_errno(L_ERROR, "Allocation failed");
return NULL;
}
@ -200,7 +200,11 @@ static struct wlr_input_device *allocate_device(struct wlr_wl_backend *backend,
struct wlr_input_device *wlr_device = &wlr_wl_dev->wlr_input_device;
wlr_input_device_init(wlr_device, type, &input_device_impl,
name, vendor, product);
list_add(backend->devices, wlr_device);
if (list_add(backend->devices, wlr_device) == -1) {
wlr_log_errno(L_ERROR, "Allocation failed");
free(wlr_wl_dev);
return NULL;
}
return wlr_device;
}