From 1580be68fda378e640aa92f5072d6b4366c03454 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Fri, 11 Aug 2017 16:05:41 +0300 Subject: [PATCH] compositor-wayland: move output init into common, fix error path Move the weston_output_init() call into wayland_output_create_common(). This avoids passing the name twice to different functions, and follows the precedent set in "libweston: weston_output_init(..., +name)" for calling init before accessing fields. Since the error paths in wayland_output_create_for_parent_output() and wayland_output_create_fullscreen() are now guaranteed to have weston_output init'd, call weston_output_destroy() appropriately. There might be more to free than just the name. Signed-off-by: Pekka Paalanen Reviewed-by: Ian Ray Acked-by Daniel Stone --- libweston/compositor-wayland.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c index dee972c8..e8639a0e 100644 --- a/libweston/compositor-wayland.c +++ b/libweston/compositor-wayland.c @@ -1242,7 +1242,8 @@ err_output: } static struct wayland_output * -wayland_output_create_common(const char *name) +wayland_output_create_common(struct weston_compositor *compositor, + const char *name) { struct wayland_output *output; char *title; @@ -1262,6 +1263,8 @@ wayland_output_create_common(const char *name) } output->title = title; + weston_output_init(&output->base, compositor, name); + output->base.destroy = wayland_output_destroy; output->base.disable = wayland_output_disable; output->base.enable = wayland_output_enable; @@ -1272,12 +1275,12 @@ wayland_output_create_common(const char *name) static int wayland_output_create(struct weston_compositor *compositor, const char *name) { - struct wayland_output *output = wayland_output_create_common(name); + struct wayland_output *output; + output = wayland_output_create_common(compositor, name); if (!output) return -1; - weston_output_init(&output->base, compositor, name); weston_compositor_add_pending_output(&output->base, compositor); return 0; @@ -1337,7 +1340,7 @@ wayland_output_create_for_parent_output(struct wayland_backend *b, struct wayland_output *output; struct weston_mode *mode; - output = wayland_output_create_common("wlparent"); + output = wayland_output_create_common(b->compositor, "wlparent"); if (!output) return -1; @@ -1353,8 +1356,6 @@ wayland_output_create_for_parent_output(struct wayland_backend *b, goto out; } - weston_output_init(&output->base, b->compositor, "wlparent"); - output->base.scale = 1; output->base.transform = WL_OUTPUT_TRANSFORM_NORMAL; @@ -1375,7 +1376,7 @@ wayland_output_create_for_parent_output(struct wayland_backend *b, return 0; out: - free(output->base.name); + weston_output_destroy(&output->base); free(output->title); free(output); @@ -1388,12 +1389,10 @@ wayland_output_create_fullscreen(struct wayland_backend *b) struct wayland_output *output; int width = 0, height = 0; - output = wayland_output_create_common("wayland-fullscreen"); + output = wayland_output_create_common(b->compositor, "wayland-fullscreen"); if (!output) return -1; - weston_output_init(&output->base, b->compositor, "wayland-fullscreen"); - output->base.scale = 1; output->base.transform = WL_OUTPUT_TRANSFORM_NORMAL; @@ -1425,7 +1424,7 @@ wayland_output_create_fullscreen(struct wayland_backend *b) err_set_size: wayland_backend_destroy_output_surface(output); err_surface: - free(output->base.name); + weston_output_destroy(&output->base); free(output->title); free(output);