[PATCH weston v3 2/3] fbdev-backend: store device name into backend structure

Benoit Gschwind gschwind at gnu-log.net
Wed Apr 27 21:56:43 UTC 2016


To avoid memory corruption or leak I store a copy of the device file
name in the fbdev-backend structure.

Signed-off-by: Benoit Gschwind <gschwind at gnu-log.net>
---
 src/compositor-fbdev.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c
index d0597a6..619f969 100644
--- a/src/compositor-fbdev.c
+++ b/src/compositor-fbdev.c
@@ -59,6 +59,7 @@ struct fbdev_backend {
 	struct udev *udev;
 	struct udev_input input;
 	int use_pixman;
+	char *device;
 	struct wl_listener session_listener;
 };
 
@@ -448,8 +449,7 @@ static void fbdev_output_destroy(struct weston_output *base);
 static void fbdev_output_disable(struct weston_output *base);
 
 static int
-fbdev_output_create(struct fbdev_backend *backend,
-                    const char *device)
+fbdev_output_create(struct fbdev_backend *backend)
 {
 	struct fbdev_output *output;
 	struct weston_config_section *section;
@@ -465,10 +465,11 @@ fbdev_output_create(struct fbdev_backend *backend,
 		return -1;
 
 	output->backend = backend;
-	output->device = device;
+	output->device = backend->device;
 
 	/* Create the frame buffer. */
-	fb_fd = fbdev_frame_buffer_open(output, device, &output->fb_info);
+	fb_fd = fbdev_frame_buffer_open(output, backend->device,
+					&output->fb_info);
 	if (fb_fd < 0) {
 		weston_log("Creating frame buffer failed.\n");
 		goto out_free;
@@ -602,7 +603,6 @@ fbdev_output_reenable(struct fbdev_backend *backend,
 	struct fbdev_output *output = to_fbdev_output(base);
 	struct fbdev_screeninfo new_screen_info;
 	int fb_fd;
-	const char *device;
 
 	weston_log("Re-enabling fbdev output.\n");
 
@@ -629,9 +629,8 @@ fbdev_output_reenable(struct fbdev_backend *backend,
 		/* Remove and re-add the output so that resources depending on
 		 * the frame buffer X/Y resolution (such as the shadow buffer)
 		 * are re-initialised. */
-		device = output->device;
 		fbdev_output_destroy(base);
-		fbdev_output_create(backend, device);
+		fbdev_output_create(backend);
 
 		return 0;
 	}
@@ -684,6 +683,7 @@ fbdev_backend_destroy(struct weston_compositor *base)
 	/* Chain up. */
 	weston_launcher_destroy(base->launcher);
 
+	free(backend->device);
 	free(backend);
 }
 
@@ -778,6 +778,7 @@ fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv
 
 	backend->prev_state = WESTON_COMPOSITOR_ACTIVE;
 	backend->use_pixman = !param->use_gl;
+	backend->device = strdup(param->device);
 
 	weston_setup_vt_switch_bindings(compositor);
 
@@ -801,7 +802,7 @@ fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv
 		}
 	}
 
-	if (fbdev_output_create(backend, param->device) < 0)
+	if (fbdev_output_create(backend) < 0)
 		goto out_launcher;
 
 	udev_input_init(&backend->input, compositor, backend->udev, seat_id);
-- 
2.7.3



More information about the wayland-devel mailing list