[PATCH weston] Properly free drm configured mode variables.

Scott Moreau oreaus at gmail.com
Tue Jul 31 21:10:53 PDT 2012


---
 src/compositor-drm.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 2075a99..e7d444f 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -1777,6 +1777,14 @@ drm_restore(struct weston_compositor *ec)
 }
 
 static void
+drm_free_configured_output(struct drm_configured_output *output)
+{
+	free(output->name);
+	free(output->mode);
+	free(output);
+}
+
+static void
 drm_destroy(struct weston_compositor *ec)
 {
 	struct drm_compositor *d = (struct drm_compositor *) ec;
@@ -1786,7 +1794,7 @@ drm_destroy(struct weston_compositor *ec)
 	wl_list_for_each_safe(seat, next, &ec->seat_list, link)
 		evdev_input_destroy(seat);
 	wl_list_for_each_safe(o, n, &configured_output_list, link)
-		free(o);
+		drm_free_configured_output(o);
 
 	wl_event_source_remove(d->udev_drm_source);
 	wl_event_source_remove(d->drm_source);
@@ -2121,18 +2129,18 @@ output_section_done(void *data)
 
 	output = malloc(sizeof *output);
 
-	if (!output || !output_name || !output_mode) {
-		free(output_name);
-		output_name = NULL;
-		free(output_mode);
-		output_mode = NULL;
+	if (!output)
 		return;
-	}
 
 	output->config = OUTPUT_CONFIG_INVALID;
 	output->name = output_name;
 	output->mode = output_mode;
 
+	if (!output->name || !output->mode) {
+		drm_free_configured_output(output);
+		return;
+	}
+
 	if (strcmp(output_mode, "off") == 0)
 		output->config = OUTPUT_CONFIG_OFF;
 	else if (strcmp(output_mode, "preferred") == 0)
@@ -2147,9 +2155,9 @@ output_section_done(void *data)
 	if (output->config != OUTPUT_CONFIG_INVALID)
 		wl_list_insert(&configured_output_list, &output->link);
 	else {
-		free(output);
 		weston_log("Invalid mode \"%s\" for output %s\n",
 						output_mode, output_name);
+		drm_free_configured_output(output);
 	}
 }
 
-- 
1.7.11.2



More information about the wayland-devel mailing list