[PATCH weston v5 10/11] Enforce destruction of all backend config objects after initialization
Bryce Harrington
bryce at osg.samsung.com
Wed Apr 13 10:25:14 UTC 2016
Since the backend config struct versioning implies that there we expect
potential future descrepancy between main's definition of the config
object and the backend's, don't allow the backend to hang onto the
config object outside the initialization scope.
Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
src/main.c | 35 +++++++++++++++++++++++------------
1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/src/main.c b/src/main.c
index c499fd0..6463e7a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -657,7 +657,20 @@ load_backend_old(struct weston_compositor *compositor, const char *backend,
return backend_init(compositor, argc, argv, wc, NULL);
}
-/* Temporary function to be replaced by weston_compositor_load_backend(). */
+/** Main module call-point for backends.
+ *
+ * All backends should use this routine to access their init routine.
+ * Backends may subclass weston_backend_config to add their own
+ * configuration data, setting the major/minor version in config_base
+ * accordingly.
+ *
+ * The config_base object should be treated as temporary, and any data
+ * copied out of it by backend_init before returning. The load_backend_new
+ * callers may then free the config_base object.
+ *
+ * NOTE: This is a temporary function intended to eventually be replaced
+ * by weston_compositor_load_backend().
+ */
static int
load_backend_new(struct weston_compositor *compositor, const char *backend,
struct weston_backend_config *config_base)
@@ -796,11 +809,10 @@ load_headless_backend(struct weston_compositor *c, char const * backend,
config->base.struct_size = sizeof(struct weston_headless_backend_config);
/* load the actual wayland backend and configure it */
- if (load_backend_new(c, backend,
- (struct weston_backend_config *)config) < 0) {
- ret = -1;
- free(config);
- }
+ ret = load_backend_new(c, backend,
+ (struct weston_backend_config *)config);
+
+ free(config);
return ret;
}
@@ -896,7 +908,7 @@ load_x11_backend(struct weston_compositor *c, char const * backend,
if (weston_x11_backend_config_append_output_config(config, ¤t_output) < 0) {
ret = -1;
- goto error;
+ goto out;
}
output_count++;
@@ -917,7 +929,7 @@ load_x11_backend(struct weston_compositor *c, char const * backend,
if (weston_x11_backend_config_append_output_config(config, &default_output) < 0) {
ret = -1;
- goto error;
+ goto out;
}
}
@@ -928,16 +940,15 @@ load_x11_backend(struct weston_compositor *c, char const * backend,
if (load_backend_new(c, backend,
(struct weston_backend_config *)config) < 0) {
ret = -1;
- goto error;
+ goto out;
}
- return ret;
-
-error:
+out:
for (j = 0; j < config->num_outputs; ++j)
free(config->outputs[j].name);
free(config->outputs);
free(config);
+
return ret;
}
--
1.9.1
More information about the wayland-devel
mailing list