diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-08-16 07:21:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-16 07:21:27 -0400 |
commit | 2164adc5136e91e5d9d5d0f67f792185f1c66658 (patch) | |
tree | 8e83344aeadb70c3449baa663d02d7013c542d62 /backend/drm | |
parent | 19d6442f52743d50d10c796d7146f58c251f67fe (diff) | |
parent | 901c14c409e6e8143ade06a7478241e558cfb79c (diff) |
Merge pull request #95 from 4e554c4c/list_api
Prevent alloc errors from crashing in `list_t`
Diffstat (limited to 'backend/drm')
-rw-r--r-- | backend/drm/drm.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 424c7685..9b4cee2f 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -748,8 +748,13 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { parse_edid(&output->output, edid_len, edid); free(edid); + if (list_add(backend->outputs, output) == -1) { + wlr_log_errno(L_ERROR, "Allocation failed"); + drmModeFreeConnector(conn); + free(output); + continue; + } wlr_output_create_global(&output->output, backend->display); - list_add(backend->outputs, output); wlr_log(L_INFO, "Found display '%s'", output->output.name); } else { output = backend->outputs->items[index]; @@ -764,6 +769,10 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { for (int i = 0; i < conn->count_modes; ++i) { struct wlr_drm_output_mode *mode = calloc(1, sizeof(struct wlr_drm_output_mode)); + if (!mode) { + wlr_log_errno(L_ERROR, "Allocation failed"); + continue; + } mode->mode = conn->modes[i]; mode->wlr_mode.width = mode->mode.hdisplay; mode->wlr_mode.height = mode->mode.vdisplay; @@ -773,7 +782,11 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { mode->wlr_mode.width, mode->wlr_mode.height, mode->wlr_mode.refresh); - list_add(output->output.modes, mode); + if (list_add(backend->outputs, output) == -1) { + wlr_log_errno(L_ERROR, "Allocation failed"); + free(mode); + continue; + } } output->state = WLR_DRM_OUTPUT_NEEDS_MODESET; |